3 Replies Latest reply on Aug 24, 2006 11:02 AM by peterent

    How to pass params to a embedded Swf using SwfLoader

    isml
      Now I load a child swf using swfloader, the child needs some params passed from parent to init itself.
      I tried to call a method of child swf in the swfLoader complete event. But it seems that child swf has not constructed itself completely at that time, so exception will be thrown. At last, i have to use Application.application.parameters to communicate with each other. Is there a much better way?

      Thanks.
        • 1. Re: How to pass params to a embedded Swf using SwfLoader
          peterent Level 2
          Using the parameters property of the Application is the best way if you are passing in parameters to the loading SWF:

          <mx:SWFLoader source="something.swf?var1=value1&var2=value2&var3=value3" />

          The something.swf can get to the var1, var2, and var3 values using the parameters property of its Application tag.
          • 2. Re: How to pass params to a embedded Swf using SwfLoader
            isml Level 1
            Thanks for your good way.
            I had expected such method only worked with object and embed tags. It's amazing that it should work with SWFLoader too. Actually, I have another question. I want to listen to some event of child swf (mainly a init complete to notify the main swf it has constructed completely and prepared itself well.) As you know i can not reference child swf in SWFLoader complete event, so what is the proper time i call the addEventListener() method?

            Thanks again.
            • 3. Re: How to pass params to a embedded Swf using SwfLoader
              peterent Level 2
              The SWFLoader's complete event is fired once all of the bytes have been read which means there is still some activity to go.
              If the SWF you are loading is another Flex 2 SWF, you can use its creationComplete event to call a method in the main application.

              Application.application refers to the top-most application; parentApplication refers to a UIComponent's immediate parent Application.

              In the loading SWF you can use Application.application. someFunction() and that function can dispatch an event or do whatever you need.