关于AS3中的removeEventListener

wylog 2009-09-02 11:59:57
我在一个按钮上应用监听器,然后把一段动画应用到这个按钮上(滤镜效果).现在的问题是,我想在鼠标移出的时候,去掉这个效果,我尝试过移除监听器然后重新注册,但加载到按钮上的效果还是没有消失,为什么?

//动画序列;
var __motion_sc5:MotionBase;
if(__motion_sc5 == null) {
import fl.motion.Motion;
__motion_sc5 = new Motion();
__motion_sc5.duration = 15;

// Call overrideTargetTransform to prevent the scale, skew,
// or rotation values from being made relative to the target
// object's original transform.
// __motion_sc5.overrideTargetTransform();

// The following calls to addPropertyArray assign data values
// for each tweened property. There is one value in the Array
// for every frame in the tween, or fewer if the last value
// remains the same for the rest of the frames.
__motion_sc5.addPropertyArray("x", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
__motion_sc5.addPropertyArray("y", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
__motion_sc5.addPropertyArray("scaleX", [2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136]);
__motion_sc5.addPropertyArray("scaleY", [2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136,2.364136]);
__motion_sc5.addPropertyArray("skewX", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
__motion_sc5.addPropertyArray("skewY", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
__motion_sc5.addPropertyArray("rotationConcat", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
__motion_sc5.addPropertyArray("blendMode", ["normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal"]);
__motion_sc5.addPropertyArray("alphaMultiplier", [1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000]);

// This call to initFilters supplies the Motion with an Array
// of the fully-qualified class names of the filters in the
// target's DisplayObject.filters list, in the same order and
// indices.
__motion_sc5.initFilters(["flash.filters.BevelFilter", "flash.filters.GradientGlowFilter"], [0, 2], -1, -1);

// The following calls to addFilterPropertyArray assign data
// values for each tweened filter's properties.
__motion_sc5.addFilterPropertyArray(0, "blurX", [0,0.92857,1.85714,2.78571,3.71428,4.64285,5.57143,6.5,7.42857,8.35714,9.28571,10.2143,11.1429,12.0714,13], -1, -1);
__motion_sc5.addFilterPropertyArray(0, "blurY", [0,0.92857,1.85714,2.78571,3.71428,4.64285,5.57143,6.5,7.42857,8.35714,9.28571,10.2143,11.1429,12.0714,13], -1, -1);
__motion_sc5.addFilterPropertyArray(0, "strength", [0.00,0.03,0.06,0.08,0.11,0.14,0.17,0.19,0.22,0.25,0.28,0.31,0.33,0.36,0.39], -1, -1);
__motion_sc5.addFilterPropertyArray(0, "angle", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -1, -1);
__motion_sc5.addFilterPropertyArray(0, "distance", [6,6,6,6,6,6,6,6,6,6,6,6,6,6,6], -1, -1);
__motion_sc5.addFilterPropertyArray(0, "knockout", [false], -1, -1);
__motion_sc5.addFilterPropertyArray(0, "type", [BitmapFilterType.FULL], -1, -1);
__motion_sc5.addFilterPropertyArray(0, "quality", [BitmapFilterQuality.HIGH], -1, -1);
__motion_sc5.addFilterPropertyArray(0, "shadowAlpha", [1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00], -1, -1);
__motion_sc5.addFilterPropertyArray(0, "shadowColor", [0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff], -1, -1);
__motion_sc5.addFilterPropertyArray(0, "highlightAlpha", [1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00], -1, -1);
__motion_sc5.addFilterPropertyArray(0, "highlightColor", [0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff,0xffffff], -1, -1);
__motion_sc5.addFilterPropertyArray(1, "blurX", [0,0.642856,1.28571,1.92857,2.57143,3.21428,3.85714,4.5,5.14286,5.78571,6.42857,7.07143,7.71428,8.35714,9], -1, -1);
__motion_sc5.addFilterPropertyArray(1, "blurY", [0,0.642856,1.28571,1.92857,2.57143,3.21428,3.85714,4.5,5.14286,5.78571,6.42857,7.07143,7.71428,8.35714,9], -1, -1);
__motion_sc5.addFilterPropertyArray(1, "strength", [0.00,0.10,0.20,0.31,0.41,0.51,0.61,0.71,0.82,0.92,1.02,1.12,1.23,1.33,1.43], -1, -1);
__motion_sc5.addFilterPropertyArray(1, "angle", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -1, -1);
__motion_sc5.addFilterPropertyArray(1, "distance", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -1, -1);
__motion_sc5.addFilterPropertyArray(1, "knockout", [false], -1, -1);
__motion_sc5.addFilterPropertyArray(1, "type", [BitmapFilterType.OUTER], -1, -1);
__motion_sc5.addFilterPropertyArray(1, "quality", [BitmapFilterQuality.HIGH], -1, -1);
__motion_sc5.addFilterPropertyArray(1, "alphas", [[0.00,1.00],[0.00,1.00],[0.00,1.00],[0.00,1.00],[0.00,1.00],[0.00,1.00],[0.00,1.00],[0.00,1.00],[0.00,1.00],[0.00,1.00],[0.00,1.00],[0.00,1.00],[0.00,1.00],[0.00,1.00],[0.00,1.00]], -1, -1);
__motion_sc5.addFilterPropertyArray(1, "colors", [[0xffffff,0x000000],[0xffffff,0x000000],[0xffffff,0x000000],[0xffffff,0x000000],[0xffffff,0x000000],[0xffffff,0x000000],[0xffffff,0x000000],[0xffffff,0x000000],[0xffffff,0x000000],[0xffffff,0x000000],[0xffffff,0x000000],[0xffffff,0x000000],[0xffffff,0x000000],[0xffffff,0x000000],[0xffffff,0x000000]], -1, -1);
__motion_sc5.addFilterPropertyArray(1, "ratios", [[0,255],[0,255],[0,255],[0,255],[0,255],[0,255],[0,255],[0,255],[0,255],[0,255],[0,255],[0,255],[0,255],[0,255],[0,255]], -1, -1);

// Create an AnimatorFactory instance, which will manage
// targets for its corresponding Motion.
var __animFactory_sc5:AnimatorFactory = new AnimatorFactory(__motion_sc5);
__animFactory_sc5.transformationPoint = new Point(-0.056848, 0.000000);

// Call the addTarget function on the AnimatorFactory
// instance to target a DisplayObject with this Motion.
// The second parameter is the number of times the animation
// will play - the default value of 0 means it will loop.
// __animFactory_sc5.addTarget(<instance name goes here>, 0);
}


//鼠标悬停时
btn1.addEventListener(MouseEvent.MOUSE_OVER,stopthecirclesc5)
function stopthecirclesc5(e:MouseEvent):void
{
btn1.width=btn1_xsc5*1.1;
btn1.height=btn1_ysc5*1.1;
//btn1.alpha=0.85;

circle1.width=circle1_xsc5*1.1;
circle1.height=circle1_ysc5*1.1;

circle2.width=circle2_xsc5*1.1
circle2.height=circle2_ysc5*1.1;

//circle1.alpha=0.85;
//circle2.alpha=0.85;

circle1.stop();
circle2.stop();

//lightmoive.alpha=0.85;
lightmoive.gotoAndPlay(2);

//为元件添加渐变发光滤镜;

// Call the addTarget function on the AnimatorFactory
// instance to target a DisplayObject with this Motion.
// The second parameter is the number of times the animation
// will play - the default value of 0 means it will loop.
__animFactory_sc5.addTarget(btn1, 1);
__animFactory_sc5.addTarget(circle1, 1);
__animFactory_sc5.addTarget(circle2, 1);
__animFactory_sc5.addTarget(lightmoive, 1);

}

//鼠标移走时
btn1.addEventListener(MouseEvent.MOUSE_OUT,circlemovesc5)
function circlemovesc5(e:MouseEvent):void
{
btn1.width=btn1_xsc5;
btn1.height=btn1_ysc5;
//btn1.alpha=btn1_alphasc5;

circle1.width=circle1_xsc5;
circle1.height=circle1_ysc5;

circle2.width=circle2_xsc5;
circle2.height=circle2_ysc5;

//circle1.alpha=circle1_alphasc5;
//circle2.alpha=circle2_alphasc5;

circle1.gotoAndPlay(2);
circle2.gotoAndPlay(2);

lightmoive.alpha=0.45;
lightmoive.gotoAndStop(2);


btn1.removeEventListener(MouseEvent.MOUSE_OVER,stopthecirclesc5);
btn1.addEventListener(MouseEvent.MOUSE_OVER,stopthecirclesc5,false,0);
...全文
1041 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wylog 2010-05-12
  • 打赏
  • 举报
回复
谢谢2楼的解答
caonilaolaode 2010-04-27
  • 打赏
  • 举报
回复
效果加上去了,你移除的是按钮的事件监听器,并不是滤镜效果!当然就没有作用了!最简单的方法就是2楼所说,设置filters=null.
jesse_luzexi 2010-04-26
  • 打赏
  • 举报
回复
removeEventListener 里的参数 要包括你以前监听时的函数
nuhong 2009-09-03
  • 打赏
  • 举报
回复
代码好长,当remove的时候,设置filters=null.
xingjunli 2009-09-02
  • 打赏
  • 举报
回复
removeEventListener 时需要重设按钮效果吧

2,275

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计/Flash/Silverlight 开发 Flash流媒体开发
社区管理员
  • Flash流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧