1 Reply Latest reply on Jul 27, 2011 5:43 PM by ozDiGennaro

    SWF load problem

    Gribospl

      Hi,

      I have a problem with a component swfloader. When I load an swf file , other components contained in the container application change its size.

      for example :

       

       

      <?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"  xmlns:local="*"

                        >

           <fx:Declarations>

           </fx:Declarations>

           <s:layout>

                     <s:VerticalLayout/>

           </s:layout>

       

           <s:Image source="test.jpeg" width="100" height="100"/>

       

          

           <mx:SWFLoader source="test.swf" width="200"/>

       

      </s:Application>

       

       

      When loaded test.swf Image component changes its size.

      I'll be very grateful for your help

      greet.

        • 1. Re: SWF load problem
          ozDiGennaro Level 1

          My work is Actionscript heavy, and I've found that I have to add an event listener and adjust size after the load completes.  Here is the load and add listeners.

                          _image = new SxImage();
                          addElement(_image);  // <this> is a BorderContainer


                              _image.addEventListener(flash.events.IOErrorEvent.IO_ERROR,loadError);                   
                               _image.addEventListener(Event.COMPLETE,loadEvent);
                              _image.addEventListener(FlexEvent.CREATION_COMPLETE,loadEvent);
                              _image.addEventListener(Event.RENDER,loadEvent);                           
                              _image.addEventListener(FlexEvent.UPDATE_COMPLETE,loadEvent);

                              _image.load(urlNow);

           

          Here is the important listener for successful load, as well as an error.  (Always listen for the flash.events.IOErrorEvent.IO_ERROR event)

           

           

          private function loadEvent(event:flash.events.Event):void {
                      var mN:String = cN + ".loadEvent " + tr.enquoteEvent(event.type) + toStringSize();  // debug
                     
                      if (!loaded && event.type == FlexEvent.UPDATE_COMPLETE && _image.width && _image.height) {
                          loaded = true;
                          if (tr.traceActivationImageEvent) tr.output(mN + "image loaded ");
                         
                          var dxNew:int = _image.width + character.layoutPaddingLeft + character.layoutPaddingRight + character.borderWeight*2;
                          var dyNew:int = _image.height + character.layoutPaddingTop + character.layoutPaddingBottom + character.borderWeight*2;

           

                          setSize(dxNew,dyNew);  // my image subclass convenience function for setting width and height.
                         
                          dispatchEvent(new ActivationEvent(ActivationEvent.CREATION_COMPLETE,this));
                                         
                          _image.enabled = true;
                          _image.addEventListener(MouseEvent.CLICK,mouseEvent);
                          _image.addEventListener(MouseEvent.DOUBLE_CLICK,mouseEvent);
                      }
                      else {
                          if (tr.traceActivationImageEvent) tr.output(mN);
                         
                      }
                  }

           

           

           

                  private function loadEvent(event:flash.events.Event):void {
                      var mN:String = cN + ".loadEvent " + tr.enquoteEvent(event.type) + toStringSize();
                     
                      if (!loaded && event.type == FlexEvent.UPDATE_COMPLETE && _image.width && _image.height) {
                          loaded = true;
                          if (tr.traceActivationImageEvent) tr.output(mN + "image loaded ");
                         
                          var dxNew:int = _image.width + character.layoutPaddingLeft + character.layoutPaddingRight + character.borderWeight*2;
                          var dyNew:int = _image.height + character.layoutPaddingTop + character.layoutPaddingBottom + character.borderWeight*2;

           

                          setSize(dxNew,dyNew);
                         
                          dispatchEvent(new ActivationEvent(ActivationEvent.CREATION_COMPLETE,this));
                                         
                          _image.enabled = true;
                          _image.addEventListener(MouseEvent.CLICK,mouseEvent);
                          _image.addEventListener(MouseEvent.DOUBLE_CLICK,mouseEvent);
                      }
                      else {
                          if (tr.traceActivationImageEvent) tr.output(mN);
                         
                      }
                  }