2

我有一个我称之为的 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

我究竟做错了什么?

4

1 回答 1

6

在 ActionScript 中,非空且非空 String 被强制转换为 Boolean true

var singleStr:String = this.loaderInfo.parameters.single;
var singleBool:Boolean = singleStr == "true";
于 2012-01-26T11:48:11.607 回答