Hi guys, I'm trying to get my head around the AnimatorFactory class for the first time and keep hitting errors.
Essentially what I'm trying to do is create a game involving bugs moving around the screen. Simply straight line tweens weren't the kind of movement we wanted, so I hunted around and found the function that allows you to convert a pre-designed motion tween into AS3 code for you to use.
I've created an AnimationManager class to store the details of all the possible Motions, and each new instance of a bug is randomly assigned one of these motion paths when their 'go()' function is called. Here is the function:
public function go():void
{
_myMotion = _myAnimationManager.getAnAnimation();
_myAnimFactory = new AnimatorFactory(_myMotion);
_myAnim = _myAnimFactory.addTarget(_myBug, 1);
_myAnim.addEventListener(MotionEvent.MOTION_END, motionFinishHandler);
}
_myMotion is an instance of the Motion class, _myAnimFactory is an instance of the AnimationFactory class, _myAnim is an instance of the AnimationBase class. _myBug is a simple MovieClip that is a child of the class conatining the go() function. All variables are protected class variables.
The code compiles fine but when it runs I keep getting this error:
ReferenceError: Error #1069: Property instance454 not found on code.game.mobs.SmallFly and there is no default value.
at fl.motion::AnimatorBase$/processCurrentFrame()
at fl.motion::AnimatorFactoryBase/addTargetInfo()
at fl.motion::AnimatorFactoryBase/addTarget
The "instance454" thing seems to refer to the _myBug variable. I don't understand why this should be not found? The SmallFly class is simply a subclass of my generic "Bug" class which contains this go() function.
Good idea. Tracing the name returns the exact same name as the one in the error message :/ (In the last test run I did it was instance441 rather than instance454, but that is irrelevant I think). It is this line that is triggering the error:
_myAnim = _myAnimFactory.addTarget(_myBug, 1);
Arg, Flash hurts my brain some days.
Incidentally, I have just tried reverting back to my old basic tweening method and it works perfectly, _myBug is appearing and functioning as normal. So it shouldn't be the source of the issue. I know this problem is all going to be cause by some tiny misunderstanding but I honestly can't get my head around it just now.
Great minds think alike, I just tried that. Same problem.
I also tried commenting out the 'problem' line (e.g. _myAnim = ...), just to see if it was possibly the line before causing the error and Flash was mistakenly thinking it was the line after, no errors.
Finally, I tried making _myBug a public var (trying anything now haha) and still the same issue.
I'm not sure if this is progress or not, but I came across a post which said that display objects created dynamically couldn't be used with the AnimatorFactory. So I tried putting an instance of the image I want to move on the timeline of the SmallFly class, and got this error instead:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.motion::MatrixTransformer$/getSkewX()
at fl.motion::Animator/setTargetState()
at fl.motion::AnimatorBase/set target()
at fl.motion::AnimatorBase/play()
at fl.motion::AnimatorBase$/processCurrentFrame()
at fl.motion::AnimatorFactoryBase/addTargetInfo()
at fl.motion::AnimatorFactoryBase/addTarget()
Hmmm... If I use trace(_myAnimFactory.toString()); on the line after it is created I get a compiler error saying that there is no "toString" method (Call to possibly undefined function through reference with static type fl.motion.AnimatorFactory), even though it is listed in the official documentation.
North America
Europe, Middle East and Africa
Asia Pacific