Skip to main content
Known Participant
November 21, 2010
Answered

Time event question

  • November 21, 2010
  • 3 replies
  • 544 views

Hi, after watching the thread:

Repeat function after x seconds?

I have a question about the time event, can you make something disabled for an amount of seconds too? For an example: you have a variable that you want to go "false;" if you click "Right" or something, and after a second or so the variable go "true;" again. What i actually want to achieve here is that during an animation a variable makes you disable so you can't for an example play the "attack" animation while the "walk" animation is on.

This topic has been closed for replies.
Correct answer kglad

those two code snippets are in different scopes.

remove the code from your movieclip and attach it to a frame.  there's never a reason to attach code to an object and there are many reasons to avoid doing that.

your_mc.speed=3;

your_mc.moveable=true;

your_mc.onEnterFrame=function(){

if(Key.isDown(Key.UP)){
this.moveable = false;

setTimeout(resetF,1000,this);

}

if(Key.isDown(Key.LEFT) && this.moveable){

this._x -= speed;

}

}

function resetF(mc:MovieClip){

mc.moveable=true;

}

3 replies

Known Participant
November 21, 2010

Sorry but i dont really get it, i tried this in the movieclip:

onClipEvent(load){
moveable = true;

speed = 3;
}
onClipEvent(enterFrame){

if(Key.isDown(Key.UP)){
moveable = false;

}

if(Key.isDown(Key.LEFT) && moveable == true;){

this._x -= speed;

}

and in the frame:

if(var moveable:Boolean=false){

setTimeout(resetF,1000);

function resetF(){

moveable=true;

}

What did i do wrong :S?

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
November 22, 2010

those two code snippets are in different scopes.

remove the code from your movieclip and attach it to a frame.  there's never a reason to attach code to an object and there are many reasons to avoid doing that.

your_mc.speed=3;

your_mc.moveable=true;

your_mc.onEnterFrame=function(){

if(Key.isDown(Key.UP)){
this.moveable = false;

setTimeout(resetF,1000,this);

}

if(Key.isDown(Key.LEFT) && this.moveable){

this._x -= speed;

}

}

function resetF(mc:MovieClip){

mc.moveable=true;

}

Known Participant
November 22, 2010

Thank you very much! You solved the problem. There were only a few things in the script that i changed, as you can see in the clear script here:

speed=3;

moveable=true;

a.onEnterFrame=function(){

if(Key.isDown(Key.UP)){
moveable = false;

setTimeout(resetF,1000,moveable);

}

if(Key.isDown(Key.LEFT) && moveable == true){

this._x -= speed;

}

}

function resetF(a:MovieClip){

moveable=true;

}

P.S the movieclip is "a"

Ned Murphy
Legend
November 21, 2010

If it is a one shot deal, then you can use setTimeout().  When you click whatever intiates setting whatever variable to be false, also initiate a setTimeout(someFunction, 1000); call so that in one second someFunction is called and sets the value true again.

kglad
Community Expert
Community Expert
November 21, 2010

yes, you can use setTimeout() to delay a call to any function:

var bool:Boolean=false;

setTimeout(resetF,3000);

funciton resetF(){

bool=true;

}