简体   繁体   中英

access symbol in “external” swf AS3

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 http://www.ashcraftband.com/myspace/videodnd/ball.jpg

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"

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

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM