actionscript project compiled as swf. how can i load it with flex and use the functions it provides?

一个人想着一个人 提交于 2019-12-25 05:32:34

问题


I have an ActionScript project with several classes that i compiled as an swf using Adobe Flex (by creating an actionscript project and clicking on export -> release build)

Is there a way to load that swf so i'll be able to load it's classes and use them on a different swf ?

i know i can use the following code to load an swf file: var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);

loader.load(new URLRequest("game.swf"));
addChild(loader);

(from Loading a SWF into an ActionScript 3 project (Flex Builder)) but how can i actually create an instance of the classes i have in that swf ?

thanks!


回答1:


Have a look at this.




回答2:


You can use the function getDefinition for example to get a reference to the class to istanciate.

It will depend how your swf is loaded in what context.

//check if the class exist into applicationDomain
if (applicationDomain.hasDefinition(name)) {
  // get the class reference from applicationDomain
  var clazz:Class=Class(applicationDomain.getDefinition(name));
 // and instanciate
 var myInstance:XXX=(new clazz()) as XXX;
}



回答3:


Take a look at this URL from the Adobe LiveDocs site (Look at the section titled 'Embedding SWF files').



来源:https://stackoverflow.com/questions/1948104/actionscript-project-compiled-as-swf-how-can-i-load-it-with-flex-and-use-the-fu

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