3 Replies Latest reply on Apr 27, 2011 10:06 AM by Flex harUI

    SWFLoader complete event doesn't dispatched

    pol2095 Level 1

      Hello,

       

      I have a swf in a SWFLoader, the complete event doesn't dispatched

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="comp(event)" xmlns:s="library://ns.adobe.com/flex/spark">
           <mx:Script>
          <![CDATA[
           [Bindable]
           public var logo:Logo = new Logo();;
            public function comp(event:Event):void {
           //are.text="test";
            }
           public function loaderComp(event:Event):void {
           are.text="thest";
           event.target.content.circle1.addEventListener(MouseEvent.CLICK, clicked);
            }
      
           public function clicked(event:MouseEvent):void {
                are.text="tytu";
           }
           
          ]]>
        </mx:Script>
           <s:VGroup paddingLeft="15" paddingTop="10">
                <s:TextArea width="400" id="are"/>
                <mx:SWFLoader id="loi" source="{logo}" complete="loaderComp(event);" width="550" height="400" />
           </s:VGroup>
      </mx:Application>
      

       

      package
      {
          import flash.display.Sprite;
          import flash.events.MouseEvent;
         
          public class Logo extends Sprite
          {
              function Logo()
              {
                  var circle1:Sprite = new Sprite();
                  circle1.graphics.beginFill(0xFFCC00);
                  circle1.graphics.drawCircle(40, 40, 40);
                  addChild(circle1);
              }
          }
      }

       

      thanks

        • 1. Re: SWFLoader complete event doesn't dispatched
          Flex harUI Adobe Employee

          COMPLETE event is only for external assets that get loaded.  Your logo is a

          class in the SWF.

          • 2. Re: SWFLoader complete event doesn't dispatched
            pol2095 Level 1

            If I use creationComplete, the event is dispatched but event.target.content.circle1.addEventListener(MouseEvent.CLICK, clicked); doesn't work

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="comp(event)" xmlns:s="library://ns.adobe.com/flex/spark">
                 <mx:Script>
                <![CDATA[
                 [Bindable]
                 public var logo:Logo = new Logo();;
                  public function comp(event:Event):void {
                 //are.text='test';
                  }
                 public function loaderComp(event:Event):void {
                 are.text='thest';
                 event.target.content.circle1.addEventListener(MouseEvent.CLICK, clicked);
                  }
            
                 public function clicked(event:MouseEvent):void {
                      are.text='tytu';
                 }
                 
                ]]>
              </mx:Script>
                 <s:VGroup paddingLeft="15" paddingTop="10">
                      <s:TextArea width="400" id="are"/>
                      <mx:SWFLoader id="loi" source="{logo}" creationComplete="loaderComp(event);" width="550" height="400" />
                 </s:VGroup>
            </mx:Application>
            
            
            • 3. Re: SWFLoader complete event doesn't dispatched
              Flex harUI Adobe Employee

              Logo could be written in a way that there is no easy way to know when

              circle1 is available.

               

              It breaks OO patterns to be digging into a component to attach listeners to

              the internals.