获取swf布尔参数

时间:2012-01-26 11:33:12

标签: actionscript-3 actionscript parameters loaderinfo

我有一个swf,我称之为

/SWFUploader/upload.swf?single=true

然后在ActionScript 3中我读入了值。但它不起作用。这是我的测试代码(第一个块取自http://blogs.adobe.com/pdehaan/2006/07/using_flashvars_with_actionscr.html):

var keyStr:String;
var valueStr:String;
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (keyStr in paramObj) {
    valueStr = String(paramObj[keyStr]);
    trace(keyStr + " = " + valueStr);
}

var isSingle:Boolean = this.loaderInfo.parameters.single as Boolean;
var isSingle1:Boolean = this.loaderInfo.parameters['single'] as Boolean;
var isSingle2:Boolean = LoaderInfo(this.root.loaderInfo).parameters['single'] as Boolean;
var isSingle3:Boolean = LoaderInfo(this.root.loaderInfo).parameters.single as Boolean;
trace(isSingle + ", " + isSingle1 + ", " + isSingle2 + ", " + isSingle3);

令人沮丧的是,这是跟踪的两行:

single = true
false, false, false, false

我做错了什么?

1 个答案:

答案 0 :(得分:6)

在ActionScript中不为空且不为null将字符串转换为布尔值true

var singleStr:String = this.loaderInfo.parameters.single;
var singleBool:Boolean = singleStr == "true";