Actionscript 3 1180:调用可能未定义的方法addEventListener
我正在接受一些AS3培训,但我遇到了一个奇怪的错误 我正在尝试在AS中的运动tween结尾添加一个事件侦听器 我创建了一个tween,突出显示了帧,右键单击并将tween复制为并粘贴到电影剪辑中(我认为有更好的方法,但我不确定它是什么…) 当我尝试将侦听器添加到该代码的末尾时,我得到了错误。这是我的密码Actionscript 3 1180:调用可能未定义的方法addEventListener,actionscript-3,flash-cs5,Actionscript 3,Flash Cs5,我正在接受一些AS3培训,但我遇到了一个奇怪的错误 我正在尝试在AS中的运动tween结尾添加一个事件侦听器 我创建了一个tween,突出显示了帧,右键单击并将tween复制为并粘贴到电影剪辑中(我认为有更好的方法,但我不确定它是什么…) 当我尝试将侦听器添加到该代码的末尾时,我得到了错误。这是我的密码 import fl.motion.AnimatorFactory; import fl.motion.MotionBase; import fl.motion.Motion; import fl
import fl.motion.AnimatorFactory;
import fl.motion.MotionBase;
import fl.motion.Motion;
import flash.filters.*;
import flash.geom.Point;
import fl.motion.MotionEvent;
import fl.events.*;
var __motion_Enemy_3:MotionBase;
if(__motion_Enemy_3 == null) {
__motion_Enemy_3 = new Motion();
__motion_Enemy_3.duration = 30;
// Call overrideTargetTransform to prevent the scale, skew,
// or rotation values from being made relative to the target
// object's original transform.
// __motion_Enemy_3.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_Enemy_3.addPropertyArray("x", [0]);
__motion_Enemy_3.addPropertyArray("y", [0]);
__motion_Enemy_3.addPropertyArray("scaleX", [1.000000,1.048712,1.097424,1.146136,1.194847,1.243559,1.292271,1.340983,1.389695,1.438407,1.487118,1.535830,1.584542,1.633254,1.681966,1.730678,1.779389,1.828101,1.876813,1.925525,1.974237,2.022949,2.071661,2.120372,2.169084,2.217796,2.266508,2.315220,2.363932,2.412643]);
__motion_Enemy_3.addPropertyArray("scaleY", [1.000000,1.048712,1.097424,1.146136,1.194847,1.243559,1.292271,1.340983,1.389695,1.438407,1.487118,1.535830,1.584542,1.633254,1.681966,1.730678,1.779389,1.828101,1.876813,1.925525,1.974237,2.022949,2.071661,2.120372,2.169084,2.217796,2.266508,2.315220,2.363932,2.412643]);
__motion_Enemy_3.addPropertyArray("skewX", [0]);
__motion_Enemy_3.addPropertyArray("skewY", [0]);
__motion_Enemy_3.addPropertyArray("rotationConcat", [0]);
__motion_Enemy_3.addPropertyArray("blendMode", ["normal"]);
__motion_Enemy_3.addPropertyArray("cacheAsBitmap", [false]);
__motion_Enemy_3.addEventListener(MotionEvent.MOTION_END, hurtPlayer);
// Create an AnimatorFactory instance, which will manage
// targets for its corresponding Motion.
var __animFactory_Enemy_3:AnimatorFactory = new AnimatorFactory(__motion_Enemy_3);
__animFactory_Enemy_3.transformationPoint = new Point(0.499558, 0.500000);
// 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_Enemy_3.addTarget(<instance name goes here>, 0);
}
function hurtPlayer(event:MotionEvent):void {
this.parent.removeChild(this);
}
导入fl.motion.AnimatorFactory;
导入fl.motion.MotionBase;
导入fl.motion.motion;
进口闪光滤光片。*;
导入flash.geom.Point;
导入fl.motion.MotionEvent;
导入fl.events.*;
变量(运动)敌人(3):运动基地;;
如果(uu运动u敌人u 3==null){
__运动_敌人_3=新运动();
__运动\敌人\ 3.持续时间=30;
//调用overrideTargetTransform以防止缩放、倾斜、,
//或相对于目标创建的旋转值
//对象的原始变换。
//_uu运动_u敌人_u3.重写GetTransform();
//以下对addPropertyArray的调用将分配数据值
//对于每个tweed属性。数组中有一个值
//对于中间的每一帧,如果最后一个值
//其余帧保持不变。
__议案3.addPropertyArray(“x”[0]);
__议案3.addPropertyArray(“y”,[0]);
__例如:(1.10,1.10,1.10,1.10,1.10,1.14,1.146,1.1947,1.1947,1.1947,1.1847,1.1947,1.247,1.247,1.4,1.4,1.4,1.3,1.3,1.3,1.3,2,1.2,1.2,1.2,1.2,1.2,1,1.2,1,1,1.2,1,1,1.2,1,1,1,1,1,2,1,1,1,1,1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1(表412643),;
__例如:(1.1,1.10,1.10,1.10,1.10,1.14,1.146,1.1947,1.1947,1.1947,1.1847,1.1947 7,1.247,1.247,1.4,1.2,1.4,1.3,1.3,1.2,1.2,1.2,2,1.4,1.1,1,1.4,1,1.4,1,1,1.4,1.4,1.4,1,1,1,1.4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,(表412643),;
__动议3.addPropertyArray(“skewX”[0]);
__动议3.addPropertyArray(“歪斜”[0]);
__运动3.addPropertyArray(“rotationConcat,[0]);
__议案3.addPropertyArray(“混合模式”[“正常模式”);
__议案3.addPropertyArray(“cacheAsBitmap”,[false]);
__motion_敌军_3.addEventListener(MotionEvent.motion_END,hurtPlayer);
//创建一个AnimatorFactory实例,该实例将管理
//其相应运动的目标。
var\uuuu animFactory\u敌人\u 3:AnimatorFactory=新的AnimatorFactory(\uuu motion\u敌人\u 3);
__animFactory_敌军_3.transformationPoint=新点(0.499558,0.500000);
//在AnimatorFactory上调用addTarget函数
//实例以此运动的DisplayObject为目标。
//第二个参数是动画的次数
//将播放-默认值0表示将循环播放。
//3.添加目标(,0);
}
功能玩家(事件:MotionEvent):无效{
this.parent.removeChild(this);
}
我尝试过几个地方,都是使用animFactory\u defession\u 3变量和motion\u defession\u 3变量-两次都出现相同的错误。我从未使用过此库,但正如我看到的,motion对象只存储动画描述。您需要一个Animator实例,它将为舞台上的DisplayObject设置动画。Animator类广播MotionEvents 我会这样做:
import fl.motion.AnimatorFactory;
import fl.motion.MotionBase;
import fl.motion.Motion;
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.motion.Animator;
import flash.filters.*;
import flash.geom.Point;
import fl.motion.MotionEvent;
import fl.events.*;
var __motion_Enemy_3:MotionBase;
var animator:Animator;
var spriteToMove:DisplayObjectContainer;
if(!spriteToMove)
{
spriteToMove = new Sprite();
spriteToMove.graphics.beginFill(0xff0000, 1);
spriteToMove.graphics.drawRect(0, 0, 50, 50);
spriteToMove.graphics.endFill();
addChild(spriteToMove)
}
if(__motion_Enemy_3 == null) {
__motion_Enemy_3 = new Motion();
__motion_Enemy_3.duration = 30;
// Call overrideTargetTransform to prevent the scale, skew,
// or rotation values from being made relative to the target
// object's original transform.
// __motion_Enemy_3.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_Enemy_3.addPropertyArray("x", [0]);
__motion_Enemy_3.addPropertyArray("y", [0]);
__motion_Enemy_3.addPropertyArray("scaleX", [1.000000,1.048712,1.097424,1.146136,1.194847,1.243559,1.292271,1.340983,1.389695,1.438407,1.487118,1.535830,1.584542,1.633254,1.681966,1.730678,1.779389,1.828101,1.876813,1.925525,1.974237,2.022949,2.071661,2.120372,2.169084,2.217796,2.266508,2.315220,2.363932,2.412643]);
__motion_Enemy_3.addPropertyArray("scaleY", [1.000000,1.048712,1.097424,1.146136,1.194847,1.243559,1.292271,1.340983,1.389695,1.438407,1.487118,1.535830,1.584542,1.633254,1.681966,1.730678,1.779389,1.828101,1.876813,1.925525,1.974237,2.022949,2.071661,2.120372,2.169084,2.217796,2.266508,2.315220,2.363932,2.412643]);
__motion_Enemy_3.addPropertyArray("skewX", [0]);
__motion_Enemy_3.addPropertyArray("skewY", [0]);
__motion_Enemy_3.addPropertyArray("rotationConcat", [0]);
__motion_Enemy_3.addPropertyArray("blendMode", ["normal"]);
__motion_Enemy_3.addPropertyArray("cacheAsBitmap", [false]);
// Create an AnimatorFactory instance, which will manage
// targets for its corresponding Motion.
var __animFactory_Enemy_3:AnimatorFactory = new AnimatorFactory(__motion_Enemy_3);
__animFactory_Enemy_3.transformationPoint = new Point(0.499558, 0.500000);
// 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_Enemy_3.addTarget(<instance name goes here>, 0);
}
/*The Animator instance*/
animator = new Animator(__motion_Enemy_3, spriteToMove);
animator.addEventListener(MotionEvent.MOTION_END, onMotionEnd);
function onMotionEnd(event:MotionEvent):void {
if (spriteToMove)
{
removeChild(spriteToMove);
}
}
导入fl.motion.AnimatorFactory;
导入fl.motion.MotionBase;
导入fl.motion.motion;
导入flash.display.DisplayObjectContainer;
导入flash.display.Sprite;
导入flash.motion.Animator;
进口闪光滤光片。*;
导入flash.geom.Point;
导入fl.motion.MotionEvent;
导入fl.events.*;
变量(运动)敌人(3):运动基地;;
var动画师:动画师;
var spriteToMove:DisplayObjectContainer;
如果(!spriteToMove)
{
spriteToMove=新精灵();
spriteToMove.graphics.beginull(0xff0000,1);
spriteToMove.graphics.drawRect(0,0,50,50);
spriteToMove.graphics.endFill();
addChild(spriteToMove)
}
如果(uu运动u敌人u 3==null){
__运动_敌人_3=新运动();
__运动\敌人\ 3.持续时间=30;
//调用overrideTargetTransform以防止缩放、倾斜、,
//或相对于目标创建的旋转值
//对象的原始变换。
//_uu运动_u敌人_u3.重写GetTransform();
//以下对addPropertyArray的调用将分配数据值
//对于每个tweed属性。数组中有一个值
//对于中间的每一帧,如果最后一个值
//其余帧保持不变。
__议案3.addPropertyArray(“x”[0]);
__议案3.addPropertyArray(“y”,[0]);
__例如:(1.10,1.10,1.10,1.10,1.10,1.14,1.146,1.1947,1.1947,1.1947,1.1847,1.1947,1.247,1.247,1.4,1.4,1.4,1.3,1.3,1.3,1.3,2,1.2,1.2,1.2,1.2,1.2,1,1.2,1,1,1.2,1,1,1.2,1,1,1,1,1,2,1,1,1,1,1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1(表412643),;
__例如:(1.1,1.10,1.10,1.10,1.10,1.14,1.146,1.1947,1.1947,1.1947,1.1847,1.1947 7,1.247,1.247,1.4,1.2,1.4,1.3,1.3,1.2,1.2,1.2,2,1.4,1.1,1,1.4,1,1.4,1,1,1.4,1.4,1.4,1,1,1,1.4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,(表412643),;
__动议3.addPropertyArray(“skewX”[0]);
__动议3.addPropertyArray(“歪斜”[0]);
__运动3.addPropertyArray(“rotationConcat,[0]);
__议案3.addPropertyArray(“混合模式”[“正常模式”);
__议案3.addPropertyArray(“cacheAsBitmap”,[false]);
//创建一个AnimatorFactory实例,该实例将管理
//相应动机的目标