AS3动态地从图书馆重视影片剪辑到舞台 [英] AS3 dynamically attach MovieClip from a library to the Stage

查看:184
本文介绍了AS3动态地从图书馆重视影片剪辑到舞台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的搜查高和宽,我开始认为这可能是我的术语是$ P $从寻找答案pventing我。

I really have searched high and wide and i'm starting to think it may be my terminology that is preventing me from finding the answer.

我有一个影片剪辑在我的图书馆设置导出为ActionScript 3.0一类被称为Info_Win(它的主要将是一个弹出窗口,其内容取决于它的实例名)。

I have a MovieClip in my library set to Export to ActionScript 3.0 with a Class called 'Info_Win' (its basically going to be a pop-up window, the contents of which depends on it's instance name).

我会加入这些影片剪辑给定数量的主舞台,每个人都必须给出一个自定义实例名,让我来访问它,一旦它在舞台上(数组勾画出实例名称)。由于previously表示,影片剪辑实例名称然后将定义哪些弹出窗口中的内容会。

I will be adding a given number of these MovieClips to the main stage and each one has to be given a custom instance name that will allow me to access it once it's on the stage (an array lays out the instance names). As previously stated, the Movieclip Instance name will then define what the contents of the pop-up window will be.

下面是数组:

static public var informationWindows:Array = new Array(     
    {_informationName:"iwPanelDescription", _popupType:"3"},
    {_informationName:"iwHelpConsole", _popupType:"2"},
    {_informationName:"iwExampleInstanceName", _popupType:"1"}
);

运行通过数组并返回_informationName应该是简单的。

Running through the array and returning the _informationName should be straightforward.

我在哪里绊倒了实际控制的影片剪辑实例名称的名字。在AS2我会包一个eval()围绕论点左侧的说法。

Where I am tripping up is actually controlling the name of the MovieClip Instance names. In AS2 I would have wrapped an eval() argument around the left hand side of the argument.

我使用下面的code:打造添加剪辑,但这是不行的:

var info_win:Info_win = new Info_win();
addChild(info_win);
info_win.name = "iwPanelDescription";

在这里,如果我能得到的实例名称的问题来分类的话,我可以用一个简单的for循环来访问我所创建的数组,并动态地设置实例名称了。

From here, if I can get the instance name issue sorted then I can use a simple for loop to access the array I have created and set the instance name up dynamically.

试过这样的,但没有快乐的事情:

var mcName:String = "iwPanelDescription";
var this[mcName]:Info_win = new Info_win();
addChild(this[mcName]);

凡是可以做,以帮助将是非常感激地接受!

Anything that can be done to help would be most gratefully received!

推荐答案

你有没有考虑存储自己参考VS依托阶段?

Have you considered storing your own reference vs relying on the stage?

您可以做到这一点很容易像这样:

You could do this easily like so:

var panels:Object = { };

panels.iwPanelDescription = new Info_win();
addChild(panels.iwPanelDescription);

trace(panels.info_win); // Get a reference via panels.

和扩大对如何可以与你的 informationWindows 阵列使用:

And to expand on how this could be used with your informationWindows array:

for each (var i:Object in informationWindows) {
    trace( panels[i._informationName] );
}

如果你想动态创建这些情况下,您可以使用<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#getDefinitionByName()"相对=nofollow> getDefinitionByName() 像这样:

If you wanted to create these instances dynamically you can use getDefinitionByName() like so:

var panelClass:Class = getDefinitionByName('Info_win') as Class;
var info_win:Info_win = new panelClass();

addChild(info_win);

这篇关于AS3动态地从图书馆重视影片剪辑到舞台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆