[英]How to make a button blink/flash on mouse click?
I am very new to AS3 , right now I am trying to make a button( made in the fla with the shape tool) to blink 3 times when press like a car indicator. 我是AS3的新手,现在我正试图使一个按钮(使用形状工具在fla中制成)在像汽车指示器一样按下时闪烁3次。 I have converted it into a symbol and currently trying to program the class itself (I am not sure if I am meant to code the symbol class or the main class that is directly connected to the fla). 我已经将其转换为符号,并且当前正在尝试对类本身进行编程(不确定是要对符号类还是直接与fla连接的主类进行编码)。 Right now I have 3 class made 2 triangle (Rblinker and Lblinker) and "MAIN". 现在我有3类2个三角形(Rblinker和Lblinker)和“ MAIN”。
Biggest problem atm is that I can't seem to get the buttons to blink on a mouse click, can any body help? 最大的问题是atm似乎无法使单击鼠标的按钮闪烁,请问有什么帮助的吗? thank you 谢谢
Right now my code for "Rblinker" looks like this. 现在,我的“ Rblinker”代码看起来像这样。
package {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent
public class Rblinker extends MovieClip {
public var timer:Timer = new Timer(1000,3);
public var blink:Boolean = true;
timer.start();
public function Rblinker() {
this.addEventListener(MouseEvent.click, clickaction);
function clickaction(e:MouseEvent):void{
timer.addEventListener(TimerEvent.TIMER, timerAction);
this.alpha = 1;
}
function timerAction(e:TimerEvent):void
{
if (!blink){
this.alpha = 1;
}
else{
this.alpha = 0;
}
blink = !blink;
}
}
}
Both blinker will be have the same code. 两个闪烁器将具有相同的代码。 also would like to just use the AC3 language only 也只想使用AC3语言
Try this: 尝试这个:
public class Rblinker extends MovieClip {
public var timer:Timer = new Timer(1000,3);//tick every second, 3 times total
public function Rblinker() {
this.addEventListener(MouseEvent.CLICK, clickaction);
//add listeners in the constructor
timer.addEventListener(TimerEvent.TIMER, timerAction);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerComplete);
}
function clickaction(e:Event):void {
//on the click, hide it to start, then start the timer
this.visible = false;
timer.reset(); //reset first so it always goes 3 times even if it's clicked again before finishing
timer.start();
}
function timerAction(e:TimerEvent):void
{
//toggle the visibility of this sprite every timer tick
this.visible = !this.visible;
//or, if you want to keep using alpha (so the button can still be clicked when not visible)
this.alpha = alpha > 0 ? 0 : 1; //this is an inline if statment
}
function timerComplete(e:TimerEvent):void {
//now that the timer is totally done, make sure the item is visible again
this.visible = true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.