3 Replies Latest reply on Dec 14, 2011 4:31 PM by Flex harUI

    flex 3.6 bitmap losing data

    felipe-kwh

      I am losing the bitmapdata inside of the bitmaps image1 and image2 in the code below, its happening after the first round of ticks,

       

      so the first tick it loads image1 fine, second tick loads image 2 fine, after that the bitmaps have no data in them.

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="1000" minHeight="1000" creationComplete="create()">

                <mx:Script>

                          <![CDATA[

                                    var imagexml:XMLList;

       

       

                                    private var tempTimer:Timer = new Timer(2000,0);

                                    private var url1:Loader = new Loader();

                                    private var url2:Loader = new Loader();

                                    private var image1:Bitmap;

                                    private var image2:Bitmap;

       

                                    private function create():void{

       

                                              url1.load(new URLRequest("com/imaging/assets/image1.jpg"));

                                              url1.contentLoaderInfo.addEventListener(Event.COMPLETE,image1load);

       

                                              url2.load(new URLRequest("com/imaging/assets/image2.jpg"));

                                              url2.contentLoaderInfo.addEventListener(Event.COMPLETE,image2load);

       

                                              tempTimer.addEventListener(TimerEvent.TIMER,tick);

                                              tempTimer.start();

       

       

       

                                    }

                                    private function image1load(event:Event):void{

       

                                              var _image1:Bitmap = url1.content as Bitmap;

                                              image1 = new Bitmap(_image1.bitmapData);

       

                                    }

                                    private function image2load(event:Event):void{

                                              var _image2:Bitmap = url2.content as Bitmap;

                                              image2 = new Bitmap(_image2.bitmapData);

       

       

                                    }

                                    private var i:int=0;

                                    private function tick(event:TimerEvent):void{

                                              if(i==1){

                                                        i = 0;

       

                                                        imagePlace.load(image1);

       

                                              }else{

                                                        i = 1;

       

                                                        imagePlace.load(image2);

                                              }

                                    }

                                    protected function left(event:MouseEvent):void

                                    {

       

                                              imagePlace.load("com/imaging/assets/image3.jpg");

                                    }

       

                          ]]>

                </mx:Script>

       

       

       

       

       

                <mx:Image id="imagePlace" height="1000" width="1000"  />

                <mx:HBox>

                          <mx:Button label="Left" click="left(event)"  />

                          <mx:Button label="Right" />

       

                </mx:HBox>

       

      </mx:Application>

        • 1. Re: flex 3.6 bitmap losing data
          Flex harUI Adobe Employee

          Flex will release the bitmap data when the source changes.  It is probably better to switch between two mx:Images than to try to switch the source.

          • 2. Re: flex 3.6 bitmap losing data
            felipe-kwh Level 1

            Yes I was able to do this as well by creating a new image. Is there no flag/method for prevening flex from releasing that data?

             

            What I am most concerned about is that flex is releasing the bitmap data on a bitmap that while it is  used as the source for an image it is still its own object and entity. It seems sort of arbitrary to in this one case say, oh I am goign to release the objects you are hodling in memory because it is no longer being used in this image (even though the bitmap could be tied up doing other things).

            • 3. Re: flex 3.6 bitmap losing data
              Flex harUI Adobe Employee

              Yeah, I think it is a bug.  Either we can’t tell or didn’t check that the image is loaded externally or is embedded.  The intent was to auto-dispose external bitmaps otherwise they won’t get garbage collected