简体   繁体   English

“外部”瑞士法郎AS3中的访问符号

[英]access symbol in “external” swf AS3

I can do 2-things. 我可以做两件事。 Load an external swf, and change the color of an object. 加载外部SWF,并更改对象的颜色。 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. 我想访问已加载的swf文件中的实例名称。

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

ball.swf ball.swf

"white ball on the stage named blueball"

load.fla 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 错误#1120
access of undefined property 访问未定义的属性

NOTE 注意
swf files are all actionscript-3. SWF文件都是actionscript-3。 I've played with the publishing and security settings. 我玩过发布和安全设置。

EXPERIMENT "to understand using symbols in external swf files" 实验 “了解在外部SWF文件中使用符号”

You are missing the "root", after the swf is loaded you can reach the timeline scope using root. 您缺少“根”,在加载swf之后,您可以使用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)." “在ActionScript 3中,根属性是指已加载的SWF的主时间轴(而不是已加载另一个SWF的SWF的时间轴)。” from http://www.adobe.com/devnet/actionscript/cookbook/timeline_root.html 来自http://www.adobe.com/devnet/actionscript/cookbook/timeline_root.html

Its because the swf isnt loaded when you try to change the color. 这是因为尝试更改颜色时未加载swf。 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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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