• Advertisement
Sign in to follow this  

Flash actionscript - cooldown movie clip help

This topic is 1328 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I want to make a flash game and I code in another actionscript file.

I want to know how to make a "button" which has a cool down effect. 

I am using AS3.

 

The button can be also a movie clip (I will use click event).

Basically I am making this button when you click on it,a gun will appear and when you click on a tile , the gun will be placed and the "button" will be darkened and there will be the 'normal' mode moving from bottom to up. The player will need to wait for a while and cannot click on it.

 

Hope someone can help me.

Thanks in advance. 

 

Edit:I have posted how it looks like.

Edited by TTHCoder

Share this post


Link to post
Share on other sites
Advertisement

There are a large number of ways you could go about doing this but without a little more information it is going to be difficult to offer you more detailed advice.

Share this post


Link to post
Share on other sites

create a bool like canPlace, and set it initally to true.  if canPlace==true then you can click on the button.  once you click on the button set canPlace to false, and create a timer for however long you want, and set it so that once the timer completes, you set canPlace back to true.

 

something like this:

var CanPlace:Boolean = true;
 
Button.addEventListener(Event.CLICK, function(e:Event)){
   if(CanPlace==false) return; //can't do anything while false.
   //do your actions here.
   CanPlace = false;
   var TimerObj:Timer = new Timer(10.0, false); //set a delay of 10 seconds, and not to repeat.
   TimerObj.addEventListener(TimerEvent.TIMER_COMPLETE, function(e:TimerEvent)){
       CanPlace=true;
   }
}

 

this code probably won't compile right away(it's been awhile since i've done flash work).  It's also not the cleanest way to do this, but the concept should work.

Share this post


Link to post
Share on other sites

create a bool like canPlace, and set it initally to true.  if canPlace==true then you can click on the button.  once you click on the button set canPlace to false, and create a timer for however long you want, and set it so that once the timer completes, you set canPlace back to true.

 

something like this:

var CanPlace:Boolean = true;
 
Button.addEventListener(Event.CLICK, function(e:Event)){
   if(CanPlace==false) return; //can't do anything while false.
   //do your actions here.
   CanPlace = false;
   var TimerObj:Timer = new Timer(10.0, false); //set a delay of 10 seconds, and not to repeat.
   TimerObj.addEventListener(TimerEvent.TIMER_COMPLETE, function(e:TimerEvent)){
       CanPlace=true;
   }
}

this code probably won't compile right away(it's been awhile since i've done flash work).  It's also not the cleanest way to do this, but the concept should work.

Thanks, now I need help.

How do I stop a frame from playing using actionscript and play it and also test if the frame of the movie clip is == 1?

(e.g. 

OnClick (gun1btn){

If (canPlace == true){

gun1.x = mousex;

gun1.y = mousey;

addChild (gun1);

gun1btn.play;

}

for (gun1.currentFrame == 1){

canPlace = true;

gun1btn.gotoAndStop (1)

}

}

Sorry for no fomat

Share this post


Link to post
Share on other sites

create a bool like canPlace, and set it initally to true.  if canPlace==true then you can click on the button.  once you click on the button set canPlace to false, and create a timer for however long you want, and set it so that once the timer completes, you set canPlace back to true.
 
something like this:

var CanPlace:Boolean = true;
 
Button.addEventListener(Event.CLICK, function(e:Event)){
   if(CanPlace==false) return; //can't do anything while false.
   //do your actions here.
   CanPlace = false;
   var TimerObj:Timer = new Timer(10.0, false); //set a delay of 10 seconds, and not to repeat.
   TimerObj.addEventListener(TimerEvent.TIMER_COMPLETE, function(e:TimerEvent)){
       CanPlace=true;
   }
}
this code probably won't compile right away(it's been awhile since i've done flash work).  It's also not the cleanest way to do this, but the concept should work.
Thanks, now I need help.
How do I stop a frame from playing using actionscript and play it and also test if the frame of the movie clip is == 1?
(e.g. 
OnClick (gun1btn){
If (canPlace == true){
gun1.x = mousex;
gun1.y = mousey;
addChild (gun1);
gun1btn.play;
}
for (gun1.currentFrame == 1){
canPlace = true;
gun1btn.gotoAndStop (1)
}
}
Sorry for no fomat

You can surround code with [cod*e][/cod*e](remove the stars when you use it.)

As for your quuestion, if i understand what you want to do. You need to place a stop() inside the gun movieclips first frame.

Then the click code would look something like this:

OnClick(gun1btn){
  If(canPlace==true){
    gun1.x = mousex;
    gun1.y = mousey;
    addChild(gun1);
    gun1.gotoAndPlay(2);
    canPlace=false;
  }
  If(gun1.currentFrame!=1) return;
  gun1btn.gotoAndStop(1);
  canPlace=true;
}
Sorry about any mistakes, posting from mobile, I'll clean it up when i get home.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement