【问题标题】:Passing flashvars to Flex将 flashvars 传递给 Flex
【发布时间】:2011-07-26 17:49:49
【问题描述】:

作为第一次遇到 Flex 的 PHP 初级人员,这让我好几天都抓狂。 flashvar 包含我想在 Flex 视频组件中播放的视频源。播放器的 HTML 如下所示:

 function createPlayer(videoSource){
    document.writeln("<div id=\"player\">");
    document.writeln("<object width=\"489\" height=\"414\" FlashVars=\""+videoSource+"\">");
    document.writeln("<param name=\"player\" value=\"bin-debug/FlexPlayer.swf\">");
    document.writeln("<embed src=\"bin-debug/FlexPlayer.swf\" name=\"player\" width=\"489\" height=\"414\" FlashVars=\""+videoSource+"\">");
    document.writeln("</embed>");
    document.writeln("</object>");
    document.writeln("</div>");               
}

我尝试调用 FlexPlayer.mxml 中的 FlashVars,但它不起作用。请告诉我我必须在 mxml 的源代码中应用什么才能访问 FlashVars。

<s:VideoPlayer id="Player" left="0" top="0" width="497" height="414"
                       skinClass="MySkin" source="FlashVars"/>
    </s:Group>

【问题讨论】:

    标签: html flash flash-builder flashvars


    【解决方案1】:

    变量videoSource 包含什么?如果它是视频的 URL,仅此而已,它可能不起作用,因为 flashvars 应该是包含变量名称和值(不仅仅是值)的字符串。

    例如,flashvars="video.flv" 不起作用,但 flashvars="sourceUrl=video.flv" 可以工作,如果视频播放器使用名为 sourceUrl 的变量。

    此外,对于 object 元素,您应该为 flashvars 添加单独的 param 元素,而不是将 flashvars 作为 object 元素的属性。对于embed 元素,flashvars 是一个属性,就像您现在拥有的一样(不是标准;)

    更多信息:

    http://kb2.adobe.com/cps/164/tn_16417.html

    【讨论】:

    • 代码应该如何查找参数元素 ()
    【解决方案2】:
    <mx:Script>
        <![CDATA[
            private function init():void {
                // The FlashVars
                var obj:Object = Application.application.parameters;
                var videoSource:String = (obj.videoSource != null) ? obj.videoSource : "there was no flashVar by this name";
                trace(videoSource);
            }
        ]]>
    </mx:Script>
    

    【讨论】:

    • 其他一切都对吗?我应该只添加这个功能才能让播放器正常工作吗?
    • 没有。添加此函数会将 flashVar 放入变量中。你将不得不弄清楚其余的。
    猜你喜欢
    • 2011-01-18
    • 1970-01-01
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    • 2012-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多