动态对象初始化 As3

编程入门 行业动态 更新时间:2024-10-27 14:22:26
本文介绍了动态对象初始化 As3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我注意到在旧版本的 flash 中你可以创建一个动态类的实例.我正在创建一个游戏,该游戏将有许多不同的类,可以在舞台上展示,但不时可以.我将如何动态调用它们.例如

I notice in older version of flash you can create an instance of a dynamic class. I am creating a game that will have many different classes that can be displayed on the stage but can very from time to time. How would I go about calling them dynamically. for example

var newObject = new ["DynamicObject"]();

??

这在 As3 中可行吗??

Is this possible in As3 ??

推荐答案

我认为有两种方法可以做到:

I think there are 2 ways you can do that:

1.使用 ApplicationDomain.getDefinition('DynamicTemplate')

类似:

var DynamicClass:Class = this.loaderInfo.applicationDomain.getDefinition('DynamicTemplate') as Class; addChild(new DynamicClass);

您需要在文件初始化后执行此操作.

You would need to do this when you file has INITialized.

2.使用 getDefinitionByName() :

var DynamicClass:Class = flash.utils.getDefinitionByName('DynamicTemplate') as Class; addChild(new DynamicClass);

如果您需要一种获取类名称以创建新对象实例的方法,可以使用 describeType() 或通过实例的构造函数,但我认为无论如何你都会知道你的类.

If you need a way to get Class names to create new instances of objects, you could use describeType() or go through the instance's constructor, but I reckon you would know your classes anyway.

var TemplateObj:Class = flash.utils.getDefinitionByName(describeType(yourIntance).@name) as Class; var newObj = new TemplateObj(); var newObj2 = new yourIntance.constructor();

希望对您有所帮助,乔治

Hope this help, George

更多推荐

动态对象初始化 As3

本文发布于:2023-11-22 23:45:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619371.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   对象   动态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!