Instantiate a class from a string in ActionScript 3

放肆的年华 提交于 2019-12-01 06:12:11

The easiest method I've come up with is to simply write the classnames out, separated by semicolons, anywhere in your project.

e.g. I create an Assets.as file with this in it:

package {   

public class Assets {       

    // To avoid errors from the compiler when calling getDefinitionByName
    // just list all of the classes that are not otherwise referenced in code:
    Balloon;
    Cloud;
    FlyingHorse;
    FlyingPig;
    UFO;
    Zeppelin;       
}
}

Full code example/tutorial on this is here: http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-6/

Gab

The other option is to use the mxmlc -includes compiler argument like this:

-includes=com.mydomain.package.MyClass

http://blogs.adobe.com/cantrell/archives/2010/09/loading-classes-dynamically-in-actionscript-3.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!