1
votes

We are making a simple Flash game intended for mobile phones via Flash 5.5 using ActionScript 3.0. We are animating an array of objects vertically until they hit another object at the top of the stage. We instantiate each element of the array with one of 10 MovieClip animations. Each object has two event listeners; one to animate vertically and another to listen for a mouse click(which removes the object from the stage). We run into an issue when more than 10 objects are on the stage at one time. The issue is that the objects disappear sporadically and without explanation. We assume the problem is due to some type of memory/ garbage collection issue. Below is a snippit of our code that dispatches the MovieClip instances onto the stage.

   function dispatch(e:TimerEvent):void{
        if(count < srrayFinal.length)
        {
            addChild(sArrayFinal[count]);
            sArrayFinal[count].x = randomNumberXtart();
            sArrayFinal[count].addEventListener(Event.ENTER_FRAME, fl_AnimateVertically, false, 0, true);
            sArrayFinal[count].addEventListener(MouseEvent.CLICK, taphandler, false, 0, true);
            sArrayFinal[count].y = 480;
            count++;
        }
        else
        {
            timer.stop();
            timer.removeEventListener(TimerEvent.TIMER, dispatch);
            timer = null;
        }
   }

What can we do in order for the MovieClips to not disappear? Thanks!!!!

2
You're not showing anything in this code. Can you please update and show more code, like for example the callbacks for the ENTER_FRAME and CLICK events as well as the code where the movieclip are generated and placed into the array.user562566
I don't think the issue is with garbage collection, while you have a DisplayObject on the visual tree (via addChild) there's no way it gets collected.dain
Is there a chance that you're adding a movieclip to the stage that is already on the stage somewhere else? When ever that happens, the movieclip seems to vanish and reappear. Just a thought.Ian
Thank you Ascension Systems, we will get that code up asap. As for Dain's comment, we are making these objects in the array eligible for garbage collection (via removeChild) in the taphandler function (once they've been clicked on.). So that does make sense. However, what could possibly be responsible for them disappearing from the visual tree sporadically before we even make them eligible? Also, we think it's interesting that when we trace evt.target after it has been removed from the visual tree via clicking on it, it still traces the evt.target as [object SymbolName].Raddfood
Thank you Ian. I would explain the disappearances as simply sporadic as we can accomplish having several children instances of the same symbol on the stage at one time. The problem seems to only arise as we increase the amount of total instances in the visual tree closer towards the total amount dispatched. Another important point here is that these symbols are linked to variables which we use to fill 10 arrays each with a set # of duplicates to dispatch. Then these arrays are put into the sArrayFinal:Array which orders each of the instances randomly. Then dispatched via timer intervals.Raddfood

2 Answers

1
votes

I don't see anywhere in that code where objects are instantiated. Instead what I see are already instantiated objects being moved into place. I'm guessing what's happening is that you only have 10 objects instantiated in the first place, so when you try to dispatch a "new" one what you are actually doing is taking an existing object, moving it from wherever it is in the middle of the stage, and placing it back at the beginning.

1
votes

I have been learning AS3, more or less to have a crack at the 3d features........ Any ways i created a visually decent 3d rotational laptop

you can view it here www.parelle.com.au

my problem was graphics disappearing once certain visuals/animations had taken place, for example if you check the website link above the keyboard and screen are separate movie clips contained in another body (movie Clip) the screen is animated the keyboard wasn't, so after 10 seconds or so the screen or certain portions would simply vanish until the mouse had been moved or something had been rendered

my simple fix was to make hidden animations play with in the movie clips continuously, keeping the flash busy rendering the mc kept everything on screen

i thought i would add to the post as this bug irritated the hell out of me, i searched and searched,,, but yeah if you have the same problem i hope this fixes it for you