Skip to main content
Inspiring
April 29, 2013
Question

A little help with time for an object

  • April 29, 2013
  • 1 reply
  • 546 views

Hi there,

I need some help here: I need to define the code for an object to appear every 3 seconds and do something else 5 seconds after appearing. Do you know how to do that?

Thanks!

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
April 29, 2013

if the object is a movieclip, you can use the following but you better do some cleanup or this will eventually crash the flash player:

var appearTimer:Timer=new Timer(3000,0);

appearTimer.addEventListener(TimerEvent.TIMER,appearF);

function appearF(e:TimerEvent):void{

var mc:MovieClip=new WhateverClass();

addChild(mc);

mc.t=new Timer(5000,1);

mc.t.addEventListener(TimerEvent.TIMER,doSomethingElseF);

}

function doSomethingElseF(e:TimerEvent):void{

//do whatever else

}

SirMarleyAuthor
Inspiring
April 29, 2013

Allright, let me ask you the following:

Lets say I have object 1 and object 2...

in lvl 1 object 1 will appear in 3 secs and will say hi in 5 and object 2 will do the same but in 2,5 secs and 4

in lvl 2 object 1 will appear in 3 secs but will say hi in 4.5 secs and object 2 will appear in 2.5 and will say hi in 3.5

How can you add that into the doSomethingElseF function so when you level up you take out 500 miliseconds from the "do whatever else" thing?

kglad
Community Expert
Community Expert
April 29, 2013

use a variable for the delay time and assign that variables value using an if-statement that checks the lvl value.