【问题标题】:how to pass querystring values to swf?如何将查询字符串值传递给 swf?
【发布时间】:2011-09-29 17:35:58
【问题描述】:

这让我发疯了...根据我的研究,我应该能够将 QueryString 参数直接传递给 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

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

【问题讨论】:

    标签: apache-flex flex4 flash query-string


    【解决方案1】:

    如果您直接启动 swf,则外部接口不可用。

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

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

    【讨论】:

    • 好主意,拥有一个托管的 HTML 页面通常是一个更好的主意。除了快速分发给朋友以便他们可以试用您的项目之外,我想不出为什么要在浏览器中直接调用 SWF。
    • 该 swf 用于直接使用 swfs 的 3d 应用程序中,所以我不能有一个 html 包装器
    【解决方案2】:

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

    //在oncreationcomplete方法中

    this.userId = this.parameters.userId;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-04
      • 1970-01-01
      • 2011-10-19
      • 2020-05-13
      • 2020-06-02
      • 2019-02-15
      • 2021-03-03
      • 1970-01-01
      相关资源
      最近更新 更多