Leo*_*ban 0 flash timer event-handling actionscript-3 mouseevent
所以今天我的问题是如何通过Timer事件和Mouse事件触发1个功能?我试图避免重新编写/重命名函数只是因为我还有一个触发它的鼠标事件而不仅仅是一个Timer事件.
问题:
我有一个addThis气泡淡入按钮翻转图标,addThis气泡将在计时器完成后淡出,但我也有一个关闭按钮在该气泡需要使用与计时器使用相同的功能.(想避免编写2个完全相同的函数)
我希望这有一个简单的解决方法,像这样的事件:null或其他东西.
定时器事件:
private function overShareButton(event:MouseEvent):void
{
shareIconsTimer = new Timer(3000,1);
shareIconsTimer.addEventListener(TimerEvent.TIMER, fadeOutShareIcons);
shareIconsTimer.start();
fadeInShareIcons();
}
Run Code Online (Sandbox Code Playgroud)
关闭按钮事件:
shareIcons.btn_closeIcons.addEventListener(MouseEvent.MOUSE_UP, fadeOutShareIcons);
Run Code Online (Sandbox Code Playgroud)
addThis Bubble Fade out功能:
// Fade out the addThis Icons
private function fadeOutShareIcons(e:TimerEvent):void
{
shareIcons.buttonMode = false;
shareIcons.btn_closeIcons.buttonMode = false;
shareIcons.btn_email.buttonMode = false;
shareIcons.btn_facebook.buttonMode = false;
shareIcons.btn_myspace.buttonMode = false;
shareIcons.btn_digg.buttonMode = false;
shareIcons.btn_delicious.buttonMode = false;
shareIcons.btn_favorites.buttonMode = false;
shareIcons.btn_twitter.buttonMode = false;
shareIcons.btn_google.buttonMode = false;
shareIcons.btn_messenger.buttonMode = false;
shareIcons.btn_stumbleupon.buttonMode = false;
// STOP TIMER & Remove share icon button events...
shareIconsTimer.stop();
shareIconsTimer.removeEventListener(TimerEvent.TIMER, fadeOutShareIcons);
shareIcons.btn_email.removeEventListener (MouseEvent.MOUSE_UP, addThisToEmail);
shareIcons.btn_facebook.removeEventListener (MouseEvent.MOUSE_UP, addThisToFacebook);
shareIcons.btn_myspace.removeEventListener (MouseEvent.MOUSE_UP, addThisToMyspace);
shareIcons.btn_digg.removeEventListener (MouseEvent.MOUSE_UP, addThisToDigg);
shareIcons.btn_delicious.removeEventListener (MouseEvent.MOUSE_UP, addThisToDelicious);
shareIcons.btn_favorites.removeEventListener (MouseEvent.MOUSE_UP, addThisToFavorites);
shareIcons.btn_twitter.removeEventListener (MouseEvent.MOUSE_UP, addThisToTwitter);
shareIcons.btn_google.removeEventListener (MouseEvent.MOUSE_UP, addThisToGoogle);
shareIcons.btn_messenger.removeEventListener (MouseEvent.MOUSE_UP, addThisToLive);
shareIcons.btn_stumbleupon.removeEventListener (MouseEvent.MOUSE_UP, addThisToStumbleupon);
TweenLite.to(shareIcons, .2, {alpha:0});
}
Run Code Online (Sandbox Code Playgroud)
我现在唯一的选择是创建另一个函数来处理关闭按钮MouseEvent,任何提示/想法赞赏!:d
你在这里的问题是你已经输入了你的fadeOutShareIcons论点TimerEvent,所以它只能接受TimerEvent.
由于MouseEvent和TimerEvent降落距离Event,你可以用它这样既可以一起工作.如果您还想在不带参数的情况下调用相同的函数,则可以传递设置为null的默认值.
情况1
private function fadeOutShareIcons(e:Event):void
Run Code Online (Sandbox Code Playgroud)情况2使用默认参数,因此您可以调用 fadeOutShareIcons()
private function fadeOutShareIcons(e:Event=null):void
Run Code Online (Sandbox Code Playgroud)您还可以检查您检查事件类型的事件:
private function fadeOutShareIcons(e:Event=null):void {
if (e==null) {
// call directly
} else if (e.type==MouseEvent.MOUSE_UP) {
// came from mouse event
} else if (e.type==TimerEvent.TIMER) {
// came from timer event
}
//...
}
Run Code Online (Sandbox Code Playgroud)