• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Array values missing

Community Beginner ,
Apr 05, 2012 Apr 05, 2012

Copy link to clipboard

Copied

I have an odd problem, odd to me anyway. It seems some of the values in my array go missing.  I load in some swfs, capture some screenshots from them as Bitmaps, and place all those bitmaps in an array.  I access that array and display the contents on screen as part of my application loading, When I try to access that array later via a mouse over, most of bitmaps in the array are gone, but some remain (generally the last few).

I am placing the array in a robotlegs singleton as I need them periodically throughout my application.  I am thinking this has something to do with memory issue or garbage collection, but not sure, any advice would be great,

Thanks,

TOPICS
ActionScript

Views

753

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 05, 2012 Apr 05, 2012

Copy link to clipboard

Copied

as long as your array references still exist, nothing they point to (your bitmaps) will be gc'd.

use the trace() function to debug your problem.  exactly how to do that depends on your coding.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 06, 2012 Apr 06, 2012

Copy link to clipboard

Copied

I have been working through this problem, and I found that the actual bitmapData is being set to null after each push to the array. So for example, on index 1 of the array, index 0 now shows null for bitmap data.

Here is the process and some code:


I load a external swf via a swfLoader, once the swf is loaded, I call another function createScreenShots(swf);  within that handler method and pass it a reference to the loaded swfLoader object. rinse and repeat until all my external swfs are loaded in and screenshots of them have been created.

within the  createScreenShots() Method

private function createScreenShots(loadedSwf:SWFLoader):void

{

        var clip:MovieClip = loadedSwf.content as MovieClip;

       clip.gotoAndStop(clip.totalFrames);

        var rawScreenData:BitmapData = new BitmapData(contentModel.clipWidth, contentModel.clipHeight, true, 0x000000);

        rawScreenData.draw(clip);

       var screenShot:Bitmap = new Bitmap(rawScreenData, "auto", true);

       _screenshotArray.push(screenShot);

       //dispatch event that will carry a copy of as single screenshot as a payload

       dispatch(new ScreenShotEvent(ScreenShotEvent.SEND_SCREENSHOT, screenShot));

}

The second iteration of this method seems to set the bitmap data to null within the previous index of the array, thus when I reference the images from within the array later, all but the last 1 or 2 have data.

Any ideas or other suggestions?

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 06, 2012 Apr 06, 2012

Copy link to clipboard

Copied

Where is contentModel coming from that you use the contentModel.clipWidth and contentModel.clipHeight?

You really should put a trace() in that function as mentioned, or a breakpoint and run it in debug, so you can watch every time that _screenshotArray is accessed and what the contents of it is.

Otherwise I see no problem with your logic as long as the last frame (clip.totalFrames) contains the screenshot you really want and no code up till that point was necessary to create the graphics at that point in time because you're skipping right to the end.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2012 Apr 06, 2012

Copy link to clipboard

Copied

i do see a problem with that goto.  i'm not sure that's the cause of the problem you're reporting but when you execute a goto, the player doesn't advance the frame and render the new frame's contents immediately.

use the render event after invalidating your stage to ensure you're making a bitmap of the last frame's contents:

private function createScreenShots(loadedSwf:SWFLoader):void

{

        var clip:MovieClip = loadedSwf.content as MovieClip;

       clip.gotoAndStop(clip.totalFrames);

if(clip.stage){

clip.addEventListener(Event.RENDER,renderF):

clip.stage.invalidate();

} else {

trace("fix this so you have a reference to a display list object")

}

}

private function renderF(e:Event):void{

trace(contentModel.clipWidth,contentModel.clipHeight);  // make sure this not 0,0

        var rawScreenData:BitmapData = new BitmapData(contentModel.clipWidth, contentModel.clipHeight, true, 0x000000);

rawScreenData.draw(e.currentTarget);

       var screenShot:Bitmap = new Bitmap(rawScreenData, "auto", true);

       _screenshotArray.push(screenShot);

       //dispatch event that will carry a copy of as single screenshot as a payload

       dispatch(new ScreenShotEvent(ScreenShotEvent.SEND_SCREENSHOT, screenShot));

}


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 06, 2012 Apr 06, 2012

Copy link to clipboard

Copied

LATEST

@sinious

The contentModel is a Robot Legs singleton that is holding an int value set when the property in the model object is initialized.  I have traced it out, that is how I know the bitmap data within the array is being set to null after the second iteration of the creatScreenShot() method.  I can’t seem to figure out why that would happen as the array still shows a bitmap object as a value for each index. Just all previous indexes of the array, the bitmap data within the bitmap object is set to null, This causes (or at least I think causes) the image not to show when I later call it to place it in a spark image component.

@Kglad

The goto seems ok as I can see the image when it is placed into a spark image component via the ScreenShotEvent.SEND_SCREENSHOT event so I think the goto is good. As mentioned to Sinious, I just can’t seem to figure out why when I push that bitmap into the  _screenshotArray it seems to set the previous indexed bitmap data  value of the bitmap object to null.

I’ll see if I can upload a screenshot to better illustrate my problem.

UPDATE:

Ok, as i was making screenshots, it seems the bitmap data is no longer being  set to null, so looks like it is fixed. Not sure as I changed nothing, but it seems to be working now and I am still no wiser as to why it was causing me two days of headaches.  But, whatever it works now so I guess all is good.

Thanks for your help and input guys.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines