Flex 4 - 在应用程序中重写SWF

时间:2010-11-13 01:26:51

标签: flex flash builder params

我没有处理试图找出将参数传递给嵌入式SWF的问题,而是继续使用不同的值编译了20个SWF。这些SWF现在位于我的Flash Builder应用程序中。

每个SWF都有一个状态(使用includeIn),因此当用户单击按钮切换状态时,将显示相应的SWF。

问题是当用户查看SWF时,它仍然在后台加载并运行。我想在用户离开状态时卸载已查看的SWF,然后在需要时再加载它。如果这是不可能的,那么我将决定在进入状态时简单地重新加载SWF,并让其他19在后台运行。

我有以下内容:

<fx:Script><![CDATA[

    private var flashMovie1:MovieClip;
    private var flashMovie2:MovieClip;

    private function initFirst():void{
        flashMovie1 = dmp_first.content as MovieClip;
    }

    private function initSecond():void{
        flashMovie2 = dmp_second.content as MovieClip;
    }

    protected function btnFirst_clickHandler():void
    {
        flashMovie2.Stop();
        currentState='First';
        flashMovie1.Play();
    }

    protected function btnSecond_clickHandler():void
    {
        flashMovie1.Stop();
        currentState='Second';
        flashMovie2.Play();
    }

]]></fx:Script>

<mx:SWFLoader id="dmp_first" includeIn="First" source="assets/images/dmp_first.swf" complete="initFirst()"/>

<mx:SWFLoader id="dmp_second" includeIn="Second" source="assets/images/dmp_second.swf" complete="initSecond()"/>

除了以上代码完全没有使用停止和播放,我仍然无法弄清楚如何强制SWF重新加载。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

使用容器一次只能有一个swf。此外,您不必使用状态:),例如:

<?xml version="1.0" encoding="utf-8"?>
<s:Application 
xmlns:fx    = "http://ns.adobe.com/mxml/2009" 
xmlns:s     = "library://ns.adobe.com/flex/spark" 
xmlns:mx    = "library://ns.adobe.com/flex/mx" 
minWidth    = "955" 
minHeight   = "600">

<s:layout>
    <s:VerticalLayout/>     
</s:layout>

<fx:Script>
    <![CDATA[
        import mx.controls.SWFLoader;

        private function onAppCreationComplete():void
        {
            showSWF(0);
        }

        private function onSwfComboChange():void
        {
            showSWF(cbxSwfData.selectedIndex);
        }

        private function showSWF(index:int):void
        {
            grpContainer.removeAllElements();

            var swfLoader:SWFLoader = new SWFLoader();
            grpContainer.addElement(swfLoader);
            swfLoader.load("assets/swfs_files/swf"+index+".swf");
        }

    ]]>
</fx:Script>

<s:ComboBox
    id                  = "cbxSwfData"
    dataProvider        = "{['swf1','swf2','swf3']}"
    change              = "onSwfComboChange()"/>

<s:Group
    id                  = "grpContainer"
    width               = "50%"
    height              = "50%"/>

</s:Application>