views:

295

answers:

2

I can do 2-things. Load an external swf, and change the color of an object. When I put these two things together, it doesn't work. How do I change the color of the loaded swf? I want to access instance names in loaded swf files.

WHAT I WAS TOLD
I have to package it and set up a class paths. Is there an easy way for now?

alt text

ball.swf

"white ball on the stage named blueball"

load.fla

//load ball.swf
var bgLoader:Loader = new Loader();
bg_mc.addChild(bgLoader);
var bgURL:URLRequest = new URLRequest("ball.swf");
bgLoader.load(bgURL);

//change color of ball to blue "code works in ball.swf" 
var myColor:ColorTransform = blueball.transform.colorTransform; 
myColor.color = 0x066ccf; 
blueball.transform.colorTransform = myColor;

ERROR #1120
access of undefined property

NOTE
swf files are all actionscript-3. I've played with the publishing and security settings.

EXPERIMENT "to understand using symbols in external swf files"

A: 

Its because the swf isnt loaded when you try to change the color. You just need to use event and it should work

import flash.events.*;

[...]

var bgLoader:Loader = new Loader();
bgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, setMyBallColor); 
bg_mc.addChild(bgLoader);
var bgURL:URLRequest = new URLRequest("ball.swf");
bgLoader.load(bgURL);

[...]

function setMyBallColor() {
//change color of ball to blue "code works in ball.swf" 
var myColor:ColorTransform = blueball.transform.colorTransform; // bg_mc.blueball.transform.colorTransform; ?
myColor.color = 0x066ccf; 
blueball.transform.colorTransform = myColor; // same
}
RafH
Loader does not have a "complete" event -- you have to add the listener to Loader's contentLoaderInfo member:bgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, setMyBallColor);
wmid
Yea, I added the event listener, but got the same error. I took the symbol from "ball.swf" and put it in "load.swf" and THERE'S NO ERRORS, just to white balls. What's missing? I'm still not accessing the external swf.
VideoDnd
oops missed thatNot sure but to access the blueball instance i think you need to use getChildAt(0)
RafH
+3  A: 

You are missing the "root", after the swf is loaded you can reach the timeline scope using root. Consider the following:

var bgLoader:Loader = new Loader();
bg_mc.addChild(bgLoader);
var bgURL:URLRequest = new URLRequest("ball.swf");
bgLoader.load(bgURL);
bgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);

function onLoaded(event:Event):void
{
    // use root to reach the timeline scope of the loaded swf
    var loadedBlueball:MovieClip = event.target.content.root.blueball;
    //change color of ball to blue "code works in ball.swf" 
    var myColor:ColorTransform = loadedBlueball.transform.colorTransform; 
    myColor.color = 0x066ccf; 
    loadedBlueball.transform.colorTransform = myColor;

    // just adding the ball to stage, you might want to add all swf
    addChild(loadedBlueball);
}

"In ActionScript 3 the root property refers to the main timeline of the loaded SWF (and not the timeline of the SWF which loaded the other SWF)." *from http://www.adobe.com/devnet/actionscript/cookbook/timeline_root.html*

dome
I had this problem in Flash 8 with ActionScript 2, and using myContainerClip._root fixed it, thanks!
Parappa