2011-09-29 54 views
0

这是我逼疯......根据我的研究,我应该能够直接传递查询字符串参数到SWF对象,像这样:如何将查询字符串值传递给swf?

http://localhost:3000/SomeFlash/bin-debug/myFlash.swf?userId=827419

在MXML oncreationcomplete方法我已经试过如下:

// oncreationcomplete method 
    var userIdTest1:String = FlexGlobals.topLevelApplication.parameters[0]; 
    var userIdTest2:String = Application.application.parameters.userId; 
    var userIdTest3:String = this.parameters.userId; 


    // External Interface 
    ExternalInterface.addCallback("OnGameLoad", ClientParams); 


// callback method 
    protected function ClientParams(userId:String):void 
    { 
     this.userId = userId;   
    }  

http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf626ae-7feb.html

我使用Flashbuilder 4.5使用Flex 4.5.1编译器。我用一个html包装器使用mxml,但我试图通过url将参数直接传递给swf。

回答

1

经过大量测试和一些愚蠢的运气后,我发现以下内容可用于获取查询字符串参数。

//在oncreationcomplete方法

this.userId = this.parameters.userId; 
2

如果您直接启动swf,ExternalInterface不可用。

同样,我怀疑这就是queryString不可用的原因。

尝试点击托管HTML页面。 (即,http://localhost:3000/SomeFlash/bin-debug/myFlash.html?userId=827419

+0

好主意,有一个托管的HTML页面始终是通常一个更好的主意。我想不出为什么要直接在浏览器中调用SWF,而不是为了快速分发给朋友,以便他们可以试用您的项目。 – bigp

+0

swf用于直接使用swfs的3d应用程序,所以我不能有一个html包装器 – chobo

相关问题