0
votes

Rather than deal with trying to figure out the passing of parameters to an embedded SWF, I went ahead and made 20 SWF's all compiled with different values. These SWF's are now inside my Flash Builder application.

There is a state for each SWF (using includeIn) so when the user clicks the button to switch states, the appropriate SWF is displayed.

The problem is that when a user views an SWF, it remains loaded and running in the background. I would like to unload the viewed SWF when the user leaves the state and then load it when it is needed again. If this is not possible, then I will settle for simply reloading the SWF when the state is entered, and just leave the other 19 running in the background.

I have the following:

<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()"/>

Along with the above code not working at all with the Stop and Play, I still can't figure out how to force an SWF to reload. Any help would be greatly appreciated!

1

1 Answers

0
votes

You can have only one swf at a time using a conatiner. Also you donlt have to use states :) for ex:

<?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>