1 Reply Latest reply on Apr 21, 2009 10:12 AM by Flex harUI

    Loading and Unloading of swf files in SWF Loader

      Hi all,

       

      I have a doubt reg. SWF Loader.

       

      I have created two mxml files A & B.

       

      A. local.mxml

      B. SwfSample.mxml

       

      i have two labels and a button in A file and i have set values to those labels and have a method to handle the click event of the button. In B file i have loaded this A file and accessed the labels and methods using SystemManager Component and changed the values of the A file's label and accessed data from A file to B file.

       

      Here comes the problem,

       

      I have two buttons named LoadAgain and Unload

       

      When i click the Unload button, the SWF Loader unloads its content by the method i handled for  the Unload button, after that i have clicked on the LoadAgain button to load the same content of A's mxml to the SWF Loader, it loads succesfully,but i was not able to access its Label or Method from the B mxml. Please help me to solve the issue.

       

      local.mxml

       

       

       

       

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application

       

      xmlns:mx=http://www.adobe.com/2006/mxml layout="absolute">

       

       

       

       

       

       

       

       

      <mx:Script>

       

       

       

          <![CDATA[

          [

       

       

      Bindable]

       

       

       

       

       

       

       

       

       

       

       

          public var varOne:String = "This is a public variable";

       

       

       

       

       

       

       

       

       

       

       

          public function setVarOne(newText:String):void

          {

       

       

                varOne = newText;

       

          }

       

       

       

          ]]>

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      </mx:Script>

       

       

       

       

       

       

       

       

       

      <mx:Label id="lblOne" text="I am here" x="28" y="88"/>

       

       

       

       

       

       

       

       

       

      <mx:Label text="{varOne}" x="166" y="88"/>

       

       

       

       

       

       

       

       

       

       

       

      <mx:Button label="Nested Button" click="setVarOne('Nested Button Pressed');" x="28" y="114"/>

      ------------------------------------------------------------------------------------------ ------------------------------------------------------------

      SwfSample.mxml

       

       

       

       

       

      <?xml version="1.0" encoding="utf-8"?>

       

      <mx:Application

       

      xmlns:mx=http://www.adobe.com/2006/mxml layout="absolute">

       

       

       

       

       

          <mx:Script>

       

       

       

       

       

          <![CDATA[

       

       

       

       

       

       

                import mx.controls.Alert;

       

       

       

       

       

                import mx.managers.SystemManager;

       

       

       

       

       

                import mx.controls.Label;

       

       

             

                [

      Bindable]

       

       

       

       

               

                public var loadedSM:SystemManager;

       

       

       

       

       

                private function initNestedAppProps():void

                {

                    loadedSM = SystemManager(myLoader.content);

       

                }

       

       

       

       

                public function updateLabel():void

                {

                    lbl.text = loadedSM.application[

      "lblOne"].text;

                }

       

       

       

       

                public function updateNestedLabels():void

                {

                    loadedSM.application[

      "lblOne"].text = "I was just updated" ;

                    loadedSM.application[

      "varOne"] = "I was just updated";

                }

       

       

       

       

       

       

                public function updateNestedVarOne():void

                {

                     local(loadedSM.application).setVarOne(

      "Updated varOne");

                }

       

       

       

       

       

       

                public function unload():void

                {

                     myLoader.content.loaderInfo.loader.unload();

                }   

       

       

       

       

       

       

       

                public function loadAgain():void

                {

                     myLoader.load(

      "../bin-debug/local.swf");

                }

              ]]>

       

       

       

       

       

       

           </mx:Script>

       

       

       

       

       

       

       

       

      <mx:Label id="lbl" x="72" y="47"/>

       

       

       

       

       

       

       

       

      <mx:SWFLoader id="myLoader" width="438" source="../bin-debug/local.swf" creationComplete="initNestedAppProps();" y="73" height="238" x="72" alpha="1.0"/>

       

       

       

       

       

       

       

       

      <mx:Button label="Update Label Control in Outer Application" click="updateLabel();" x="72" y="319"/>

       

       

       

       

       

       

       

       

      <mx:Button label="Update Nested Controls" click="updateNestedLabels();" x="72" y="349"/>

       

       

       

       

       

       

       

       

      <mx:Button label="Update Nested varOne" click="updateNestedVarOne();" x="72" y="379"/>

       

       

       

       

       

       

       

       

      <mx:Button label="Unload" click="unload();" x="72" y="409"/>

       

       

       

       

       

       

       

       

      <mx:Button label="Load Again" click="loadAgain();" x="72" y="439"/>

      </mx:Application>

       

      Thanks & regards,

      Sathish.K