动作3:创建变量对象,并从分析的XML文件中指定的类变量、并从、对象、动作

2023-09-08 14:54:09 作者:可爱的怀抱杀

我已经设置了将包含在FLA / SWF库对象的名称的XML文件。 我想对使用可以快速修改,而无需重新编译FLA / SWF文件的XML文件在舞台上的地位的对象。当然,定位只能当对象被instantiaed并添加到阶段完成的。问题是经过解析的XML文件名/类配对数据到VAR创造编程。

I've set up an XML file with names of objects that will be contained in a fla/swf library. I wish to position the objects on the stage using an XML file that can be quickly modified without having to recompile the fla/swf file. Of course, positioning can only be accomplished when the objects are instantiaed and added to the stage. The problem is passing the parsed XML file name/class paring data into the var creation programatically.

XML文件包含的对象名称和类:例如如下:

The XML file contains the object names and class: example follows:

<objects>
   <object name="myBall" class="Ball"/>
</objects>

XML文件解析正常,我已经建立了一个......为......每个循环的名称/类分配给每个对象。 问题是用正确的语法,输入名称/类配对,类似于以下内容:

The XML file parses correctly and I've set up a ...for...each loop to assign the name/class to each object. The problem is with the proper syntax to input the name/class paring, something similar to the following:

var object.@name:object.@class = new object.@class();

我是从我的摇杆本或只是暂时无知??? **

Am I off my rocker with this or just temporarily ignorant???**

推荐答案

只是一个快速跟进,有一个很简单的方法来保持它的弹性:

Just a quick follow up, there's a quite straight forward way to keep it flexible :

var xml:XML = <object name="myBall" class="Ball">;

// Looks up for a defined symbl/definition with the name 'Ball'    
var Def:Class = getDefinitionByName(xml.@class);

// Creates the instance of the Ball
var instance:* = new Def();

// in case you want to assign a name to the node as a reference on the display list :
addChild(instance).name = @xml.name;