很明显,undefined是as3的关键字,"undefined"是一个字符串,两者完全不同。但是在使用的时候有可能会弄糊涂
比如,在网页里嵌入flash
<embed width="400" height="300" flashvars="p2=undefined" src=" ./Test.swf" type="application/x-shockwave-flash" wmode="opaque" allowfullscreen="true" allowscriptaccess="always">
as3代码
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.external.ExternalInterface;
public class Test extends Sprite
{
public function Test()
{
stage ? init() : this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(evt:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
init();
}
private function init():void
{
var parameters:Object = stage.loaderInfo.parameters;
ExternalInterface.call("console.log", parameters.p1 == undefined);
ExternalInterface.call("console.log", (parameters.p2 == undefined) + " : " + typeof(parameters.p2));
}
}
}
输出结果(在浏览器控制台看):
true
false : string