Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This can be done several different ways.</p> <p>My suggestion is that you have a Class for your man. In this class you have a function that starts the removeTimer, and that should get triggered when the man is created. When the 2 seconds is up, we remove the event Listener and remove him from his parent.</p> <p>The timer that is adding the men, should be in whatever class you want to instantiate your men in.</p> <p>Here's an example</p> <pre><code>public function initMyTimer() { var timer:Timer = new Timer(2000); timer.addEventListener(TimerEvent.TIMER, voegtoe); timer.start(); } public function voegtoe(e:TimerEvent):void { trace ('set me up'); var man:Man = new Man; man.x=Math.random()*650; man.y=Math.floor(Math.random()*(70))+350; addChild(man); man.setMyRemoveTimer(); } </code></pre> <p>Now your Man class should have these functions in it to handle the removal. Please note that from we are calling setMyRemoveTimer in the above code. You could call that function in the constructor, but I wanted to show the link here so I put it in the above code. That function will exist here in the Man Class :</p> <pre><code>public function setMyRemoveTimer():void { var removeTimer:Timer = new Timer(2000,1); removeTimer.addEventListener(TimerEvent.TIMER_COMPLETE, removeMe); removeTimer.start(); } public function removeMe(e:TimerEvent):void { var removeTimer:Timer = e.target as Timer; removeTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, removeMe); this.parent.removeChild(this); } </code></pre> <p>This is just a suggestion, many ways to do this. If you are creating many men, I think the idea of an array holding these men is a good one as has been suggested.</p> <p>But the concept here is that if the timer is a member of the Man class, the eventHandler will have access to remove the listener as well as the man from its parent.</p> <p>I don't consider this an ideal implementation, but I was trying to match your current design as best I could --ie I didn't want to go into arrays to teach this concept.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload