12 Replies Latest reply: Aug 5, 2012 8:47 AM by kglad RSS

    AnimatorFactory error

    Dinkyfish Community Member

      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.

        • 1. Re: AnimatorFactory error
          kglad CommunityMVP

          use trace(_myBug,_myBug.stage) to see what the problem is.

          • 2. Re: AnimatorFactory error
            Dinkyfish Community Member

            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).

            • 3. Re: AnimatorFactory error
              kglad CommunityMVP

              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.

              • 4. Re: AnimatorFactory error
                Dinkyfish Community Member

                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.

                • 5. Re: AnimatorFactory error
                  Dinkyfish Community Member

                  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.

                  • 6. Re: AnimatorFactory error
                    kglad CommunityMVP

                    something's out of scope. 

                     

                    comment out your listener to see if that's part of the problem.

                    • 7. Re: AnimatorFactory error
                      Dinkyfish Community Member

                      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.

                      • 8. Re: AnimatorFactory error
                        Dinkyfish Community Member

                        I also tried tracing _myBug.name from the subclass (SmallFly) and it came up no problem.

                        • 9. Re: AnimatorFactory error
                          Dinkyfish Community Member

                          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()

                          • 10. Re: AnimatorFactory error
                            kglad CommunityMVP

                            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.

                            • 11. Re: AnimatorFactory error
                              Dinkyfish Community Member

                              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.

                              • 12. Re: AnimatorFactory error
                                kglad CommunityMVP

                                the toString() method is inherited from the object class so you should cast your instance:

                                 

                                trace(Object(_myAnimFactory).toString())