Wednesday, 7 August 2013

Need actionscript 3 referenceing assistance

Need actionscript 3 referenceing assistance

hi guys im haveing a simple syntax referencing problem, im building a
video game and i have a situation where enemies come and bounce off a
castle doing dmg and you shoot arrows to kill them. when i instantiate an
enemy, before putting it in the game, i add an event listener for such
things as collision detections and so forth. now when the arrows kill the
monsters, it gets rid of the monster graphics, but since they have an
event listener on them they persist in the game environment and continue
to dmg the castle wall.
now due to coding structures in my 1300+ game line code i need to make an
external reference to strip my enemy movieclip of this onEnterFrame
eventlistener. This can be accessed in one of three ways i have set up --
1) obviously in the instantiated class when i build it (which i just
finished saying i cant do, because its actually invoked by the arrow
hitting it and being below 0 hit points)
2) Ive built them to an array: I have a global myenemyarray, which holds
each monster in the game (used mostly for collision detection) but
nonetheless they all hold an incrementing ID number for easy reference
3) inheritence: I would like to be able to point strait to it, i keep
imagining something like
stage.gameWindowMovieClip.enemyToRemoveMovieClip.removeEventListener(Event.ENTER_FRAME,
codePerFrame)
I did think of a work around but im sure it would be extremely memory
inefficent, that is, I could make option #1 work by having an enemy
variable IsDead = 0 and it would perform all of the unload routines (get
rid of listener, get rid of array splice, get rid of object on stage), the
arrow hitting the monster could modify the monster hp, and on the
perEnterFrame have it look if hp is below 0, toggle isdead on, then have
the unload invoked. This could work but it'd be incredibly sloppy and im
pretty sure memory hogging (i try to keep all instantiated objects'
perenterframes to a minimum)
anyways if anyone knows how to remove a movieclips eventlistener
(onenterframe) remotely through arrays or inheritance please share with
me, i would appreciate it, thanks ;)

No comments:

Post a Comment