我是AS3的新手,现在我正试图按下一个按钮(用形状工具在fla中制作)按下汽车指示灯时闪烁3次。我已将它转换为符号并且当前正在尝试编写类本身(我不确定我是否要编写符号类或直接连接到fla的主类)。现在我有3个类2个三角形(Rblinker和Lblinker)和“MAIN”。
最大的问题是,我似乎无法通过鼠标点击按钮闪烁,任何身体都可以帮助吗?谢谢
现在我的“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;
}
}
}
两个闪光灯都有相同的代码。也想只使用AC3语言
答案 0 :(得分:0)
试试这个:
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;
}
}