5 Replies Latest reply on Jul 24, 2010 5:09 AM by amscreen

    SWFLoader completeEvent problem




      I'm using a SWFLoader to load a SWF into my main SWF.

      Now I want to add an EventListener to the loaded application.


      So I tried putting that in the completeHandler:


      protected function swfLoader_completeHandler(event:Event):void
           Object(swfLoader.content).application.Group1.addEventListener(MouseEvent.MOUSE_DOWN, _onMousePress);


      Problem: When the completeEvent is fired swfLoader.content.application is still null.

      (The initEvent is not working either.)


      Any ideas where I should put that line?

      Or do I need to dispatch an event in the loaded SWF? Like in the application1_creationCompleteHandler?

        • 1. Re: SWFLoader completeEvent problem
          ShardulSingh Level 3

          Pls write "Application.application" instead of "Object(swfLoader.content)" because there is no 'application' property with
          "Object(swfLoader.content)" so it will always be null.


          Let me know if you have any issue with this.

          with Regards,
          Shardul Singh Bartwal

          • 2. Re: SWFLoader completeEvent problem
            mellusan Level 1

            Hi ShardulSingh,


            thank you for your reply. I still didn't solve it though.


            If I type Application in my mainSWF I get a few possibilities:


            1. spark.components.Application.

                      Here .application gets me a "possible undefined property error"


            2. mx.core.Application here I find Application.application though I get a warning:
                      3608: 'application' has been deprecated since 4.0.  Please use 'FlexGlobals.topLevelApplication'


            trace is:

            trace(mx.core.Application.application);:     null
            trace(FlexGlobals.topLevelApplication);:     mainSWF


            So how do I get to the subSWF property from that?



            btw "..it will always be null" is not quiet correct I think.

            I have a button with a clickHandler like that:


            protected function button_clickHandler(event:MouseEvent):void

                 Object(planLoader.content).application.Group1.addEventListener(MouseEvent.MOUSE_DOWN, _onMousePress);



            When I push the button after the content is fully loaded (after the completeHandler is finished) it works. But adding the EventListener with the push of a button can't be the solution

            • 3. Re: SWFLoader completeEvent problem
              Flex harUI Adobe Employee

              In the completeHandler, add an event listener to swfLoader.content for applicationComplete, then when that event fires, add your event listener as you have it there.


              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui

              • 4. Re: SWFLoader completeEvent problem
                mellusan Level 1


                Thank you very much!

                • 5. Re: SWFLoader completeEvent problem

                  _button.addEventListener(MouseEvent.CLICK, onMCButtonClick);

                  TypeError: Error #1009: null 객체 참조의 속성이나 메서드에 액세스할 수 없습니다.


                  how this problem to solve?