如果你想要一個優雅的方式Flash變量的工作,你可以使用FlashVars class從the temple library。這個類是flashvars的包裝,所以它們可以在沒有Stage的地方訪問。
您可以分別爲每個flashvar設置默認和類類型。結合使用FlashVarNames枚舉類,您可以知道應用程序中使用了哪些flashvars。
您應該在主文件中實例化/配置一次FlashVars。
package
{
import temple.data.flashvars.FlashVars;
import flash.text.TextField;
public class FlashVarsExample extends DocumentClassExample
{
private static const _LANGUAGE:String = 'language';
private static const _VERSION:String = 'version';
private static const _IS_DEMO:String = 'is_demo';
public function FlashVarsExample()
{
FlashVars.initialize(this.loaderInfo.parameters);
FlashVars.configureVar(_LANGUAGE, 'nl', String);
FlashVars.configureVar(_VERSION, 1, int);
FlashVars.configureVar(_IS_DEMO, true, Boolean);
var txt:TextField = new TextField();
txt.width = 550;
txt.height = 400;
this.addChild(txt);
trace('FlashVars.getValue(_LANGUAGE) : ' + FlashVars.getValue(_LANGUAGE) + "\n");
trace('FlashVars.getValue(_VERSION) : ' + FlashVars.getValue(_VERSION) + "\n");
trace('FlashVars.getValue(_IS_DEMO) : ' + FlashVars.getValue(_IS_DEMO) + "\n");
trace(FlashVars.dump());
}
}
}
@MartyWallace是的,我知道,但我不應該仍然得到這個錯誤。 – 2012-04-16 02:27:31