影片剪辑(根)不工作。如何从影片剪辑访问根目录变量?闪存AS3影片剪辑、根目录、闪存、变量

由网友(傲天~皇家师)分享简介:确定香港专业教育学院有一个简单的Flash文件,因为即时通讯试图完成访问影片剪辑内从主舞台的变量。所有的事情伊夫发现从谷歌指向影片剪辑(根)。但它不是为我工作。Ok Ive got a simple flash file, since im trying to accomplish accessing a varia...

确定香港专业教育学院有一个简单的Flash文件,因为即时通讯试图完成访问影片剪辑内从主舞台的变量。所有的事情伊夫发现从谷歌指向影片剪辑(根)。但它不是为我工作。

Ok Ive got a simple flash file, since im trying to accomplish accessing a variable from the main stage inside a movie clip. All the things Ive found from google point to MovieClip(root). But its not working for me.

在主时间轴:

var MyName:String;
MyName = "kenny";

然后,我有一个名为myBox上的影片剪辑,它的code:

Then I have a movieclip called MyBox, its code:

trace(MovieClip(root).MyName);

和我得到这个错误:类型错误:错误#1034:类型强制失败:无法转换flash.display使用::舞台@ 2d2df089到的flash.display.MovieClip。     在myBox上/ sendpmtext()

And I get this error: TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Stage@2d2df089 to flash.display.MovieClip. at MyBox/sendpmtext()

我也尝试影片剪辑(父),影片剪辑(parent.parent),影片剪辑(第一阶段),影片剪辑(this.stage)和没有运气。任何帮助吗?

I have also tried MovieClip(parent), MovieClip(parent.parent), MovieClip(stage), MovieClip(this.stage) and no luck. Any help please?

推荐答案

您可以只是做

parent["MyName"];

或者,在主时间轴的正确铸造(在你的情况下,家长型MainTimeline的):

OR, a proper casting of the main timeline (in your context, the parent is of type MainTimeline):

MainTimeline(parent).MyName;

父始终是一个的DisplayObjectContainer ,其中有创建没有特殊的属性。如果创建自定义属性,那么你需要转换为具有这些自定义属性的类,然后就可以通过域名来访问它们。 (编译器,否则不知道它们的存在,并给出了这样的错误)。

Parent is always a DisplayObjectContainer, which has no special properties you create. If you create custom properties, then you need to cast to the class that has those custom properties before you'll be able to access them by name. (the compiler otherwise doesn't know they exist, and gives you that error).

是指您的SWF的最上级。你的主时间轴实际上是阶段的孩子,所以在主时间轴上的VAR /对象/方法不是阶段的一部分

root refers to the topmost stage of your swf. Your main timeline is actually a child of stage, so vars/objects/methods on the main timeline are not a part of stage

如果您使用 stage.addChild(myBox上),然后是父,而不是主时间轴。如果由于某种原因,你需要有舞台的父母,那么你就必须保持一个参考mainTimeline的地方,你可以访问。您可以创建一个变种做到这一点在你的myBox上的时间表。

If your using stage.addChild(MyBox), then stage is the parent, and not the main timeline. If for some reason you need to have stage as the parent, then you'd have to keep a reference to the mainTimeline somewhere you can access. You could create a var to do this in your MyBox timeline.

var mainTimeline:MainTimeline;

然后在主时间轴code,做到这一点:

Then in the main timeline code, do this:

MyBox.mainTimeline = this;

然后,你可以通过做内myBox上访问你的变种 mainTimeline.MyName;

阅读全文

相关推荐

最新文章