1

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!!!!

Raddfood
  • 169
  • 2
  • 4
  • 17
  • 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. –  Jun 04 '11 at 11:11
  • 2
    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 Jun 04 '11 at 12:56
  • 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 Jun 04 '11 at 16:53
  • 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 Jun 04 '11 at 16:54
  • 1
    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 Jun 04 '11 at 17:09

2 Answers2

1

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.

jhocking
  • 5,527
  • 1
  • 24
  • 38
  • Thank you for your answer. I see exactly what you mean about moving around one object instead of creating new ones. Now this brings us to our real problem, which is generally speaking, how does one take a symbol from the library and create copies of it in code? We are working with lots of instances and only 10 objects, so how could we effectively "dispatch new objects" of the same symbol? Moreover, how do we then get rid of them for a new level? Again, thank you very much, this of course, was major shortsightedness on our part. – Raddfood Jun 04 '11 at 20:27
  • The MovieClips in your library have to be linked to the code. Then in the code use the "new" keyword to instantiate copies. – jhocking Jun 04 '11 at 20:45
  • jhocking you are absolutely right. When we try to dispatch a new object of a type already on the screen, the object on the screen disappears and is repositioned at the bottom of the screen. This is because we reference the instantiation of the object more than once. Thank you so much! – Raddfood Jun 05 '11 at 00:20
1

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