开发者

AS3 - Objects on stage unintentionally disappear

开发者 https://www.devze.com 2023-03-11 12:01 出处:网络
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开发者_如何学Python hit another object at th

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开发者_如何学Python 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!!!!


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消