Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
use trace(_myBug,_myBug.stage) to see what the problem is.
Copy link to clipboard
Copied
I get [object SmallFlyImg] [object Stage] as the output, which is exactly as I would expect. In this case _myBug will be an instance of SmallFlyImg (Small Fly Image).
Copy link to clipboard
Copied
what's trace(_myBug.name)?
and click file/publish settings/swf and tick permit debugging. when you retest note the line number triggering the error message.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
something's out of scope.
comment out your listener to see if that's part of the problem.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I also tried tracing _myBug.name from the subclass (SmallFly) and it came up no problem.
Copy link to clipboard
Copied
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()
Copy link to clipboard
Copied
dynamically created objects CAN be used with the AnimatorFactory. that's not the problem.
there's something else about your setup that's causing the problem. i'm not sure if the problem is because _myMotion or _myBug is out of scope.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
the toString() method is inherited from the object class so you should cast your instance:
trace(Object(_myAnimFactory).toString())