5 Replies Latest reply on Jul 5, 2006 5:23 PM by jpwrunyan

    SWFLoader/Image complete event problem (bug?)

    jpwrunyan Level 1
      I have an SWFLoader in my application whose content is dynamically bound to a datagrid for loading different images. Depending on the new image size I want to make some adjustments, etc. to the SWFLoader itself... that's not important for now.

      The problem is that if I take the width of the SWFLoader instance on the "complete" event, it gives the value for the PREVIOUS image setting so my math function is useless.

      Try this to see what I mean:
      public var imageSource:String;

      private function temp():void {
      mx.controls.Alert.show("imgLoader.width: "+imgLoader.width);
      <mx:Button click="imageSource='someImageURL'" />
      <mx:SWFLoader id="imgLoader" autoLoad="true" source="{imageSource}" complete="temp()" />

      if you implement the above code, and assuming that imageSource is a null string upon initialization, you will get a value of "0" for the imgLoader instance's width when you load a new image.

      To get around this in Flex 1.5 I could use doLater(this, "temp") but doLater appears to have been removed in Flex 2.0.

      My current work around is to modify the above code as follows:

      private function temp():void {
      this.addEventListener("enterFrame", blorch);
      private function blorch(b:Event):void {
      mx.controls.Alert.show("imgLoader.width: "+imgLoader.width);
      this.removeEventListener("enterFrame", blorch);

      feels like a hack to me... is there no way to get this to work without using the above functions? Sort of seems pointless to have removed "doLater" just to make me write a function that essentially does the same thing in Flex 2.0. I tried using the "resize" event in place of "complete" and that works... if the image loaded is a different size than the previous one. If the image is the same size (as is often the case in my application) then it doesn't work.

      Any suggestions Adobe/Macromedia, fellow developers?