1180: Call to a possibly undefined method addEventListener

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2011-01-06T22:05:57Z Indexed on 2011/01/07 0:54 UTC
Read the original article Hit count: 246

Filed under:
|

I'm going through some AS3 training, but I'm getting a weird error...

I'm trying to add an event listener to the end of a motion tween in AS.

I've created a tween, highlighted the frames, right clicked and copied the tween as AS and pasted it into the movie clip (I think there's a better way to do this, but I'm not sure what it is...)

When I try to add the listener to the end of that code, I get the error. Here's my code.

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);
}

I've tried a few places for it, both with the animFactory_Enemy_3 variable and the motion_Enemy_3 variable - getting the same error both times.

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about flash-cs5