我正在开发一个网站,其中包含从上到下覆盖整个舞台的导航项目(请参见下面的更改图像),用户很容易用鼠标退出舞台,而不是触发MouseEvent.MOUSE_OUT
“关闭”所需的事件说导航项目。
我应该Event.MOUSE_LEAVE
用来检测鼠标何时离开舞台,并关闭任何启用的导航项目吗?这就是我一直在尝试做的事情,但是在从我的听众那里获得任何输出时遇到了麻烦。有任何想法吗?
替代文字 http://marcysutton.com/blog/wp-content/uploads/2010/01/redpropeller.png
对于与 Flash IDE 中的影片剪辑关联的类,这是注册Event.MOUSE_LEAVE
侦听器的正确语法吗?无论我做什么,它似乎都没有做任何事情。是否必须将电影嵌入浏览器才能触发事件?
this.stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveListener);
这是我的 MainNav.as 课程:
package com.redpropeller {
import com.greensock.*;
import com.greensock.plugins.*;
import flash.display.*;
import flash.text.*;
import flash.events.*;
public class MainNav extends MovieClip { // MainNav is a movieclip in the IDE
public var colors:Array;
public function MainNav():void {
colors = new Array(0xee3124, 0xc72a1f, 0xa62c24, 0x912923, 0x7e221c);
TweenPlugin.activate([TintPlugin]);
// trying to target stage through this object
this.stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveListener);
for(var i:Number=0; i<this.numChildren; i++){
var n = this.getChildAt(i);
n.useHandCursor = true;
n.buttonMode = true;
n.addEventListener(MouseEvent.MOUSE_OVER, navBtnOn);
n.addEventListener(MouseEvent.MOUSE_OUT, navBtnOff);
}
}
public function mouseLeaveListener(e:Event):void {
trace('mouseleave'); // nothing ever happens
}
private function navBtnOn(e:MouseEvent):void {
TweenLite.to(e.currentTarget.bar_mc, 0.01, {tint:0x333333});
}
private function navBtnOff(e:MouseEvent):void {
TweenLite.to(e.currentTarget.bar_mc, 0.01,
{tint:uint(colors[this.getChildIndex(MovieClip(e.currentTarget))])});
// changes color back to specific tint
}
}
}