2014-04-18 57 views
0

我在项目中执行https://code.google.com/p/as3scriptinglib/时遇到问题。as3scriptinglib(动态代码加载)正在编译代码但未执行

该代码已编译,但它不会被执行。

public function Main():void { 
    var loader:CompilerLoader = new CompilerLoader(); 
    loader.addEventListener(CompilerEvent.INIT, compilerInit); 
    loader.load("ESCompilerSWF.swf"); 
    trace("INIT"); 
} 

private function compilerInit(event:CompilerEvent):void { 
    var compiler:ICompiler = event.compiler; 
    trace("PREPARE",compiler.initialized); 
    var str:String = 'trace("HELLO WORLD");'; 
    try { 
     var script:IScript = compiler.compileAndLoad(str, new ScriptContext(this)); 
     script.addEventListener(ScriptErrorEvent.SCRIPT_ERROR, trace); 
     trace("Script created"); 
    } catch (e:Error) { 
     trace("ERROR", e.message); 
    } 
    trace("READY"); 

} 

,并将其输出:

INIT 
PREPARE true 
Script created 
READY 

所以,你可以看到代码不被执行as3scriptinglib。 帮助。

回答

0

我已经解决了这个问题。时执行的脚本类是垃圾回收,所以我改变:

var script:IScript = compiler.compileAndLoad(str, new ScriptContext(this)); 

给一个变量的函数外,如:

script = compiler.compileAndLoad(str, new ScriptContext(this)); 

和它的作品。

:)