6 Replies Latest reply on Jan 15, 2007 10:34 AM by serik.george

    Animation struggles

    Hampigato
      Hi there, folks!
      I'm having some difficulties with 'this' and '_root' which I'm hoping you could help me with. I've built a move clip prototype function and the main problem i've run into is the hard brackets.

      usually in movieclip.prototypes you would use 'this' to refer to the movieclip being passed but i can't get it to work with this.
      the problem is that i'm trying to get some values for a 2d array which ive stored the animation information in.
      i store the information like this:

      bill.animationWalk = function() {}
      bill.animationWalk = {start:15, end:21, looping:true}

      this is being written for every different movieclip and for every type of animation.

      when i try to get the information in the movieclip.prototype i do like this:

      MovieClip.prototype.Animation = function(animId) {
      ...

      this.gotoAndPlay(this[Type]["animation"+animId].start)

      ...
      }

      MovieClip.prototype.Animation = function(animId) {
      ...
      trace(_root[Type])
      trace(this[Type])
      ...
      }

      both of the traces returns undefined. i know that the [Type] is being correctly stored so thats not the issue.
      Anyways, if anyone have any thoughts at all, im hoping you're willing to share them.

      Thanks in advance.
        • 1. Re: Animation struggles
          ∞_infinite
          Hi Hampigato,
          I think you have a escope problem here. Before starting the prototype block assign a var called thisObj like this:
          var thisObj = this;

          by doing this you are saving a refence to the 'this' object but in the original scope in a local variable. Now try to use thisObj instead of 'this' where you want to get information about the original scope.

          If this code is on a event handler like onRelease or something like this, post the complete code because then you'll have some trouble.
          • 2. Animation struggles
            Hampigato Level 1
            I've tried your suggestion without any progress.
            I've attached the function if you might want to take a look at it.

            One thing I've been wondering about is how the use of the hard brackets in this piece of code will output:

            thisObj[Type]["animation"+animId].end

            lets say the Type == "bill" and the animId == "Stand"
            will it then show this:

            bill.animationStand.end
            ?
            • 3. Animation struggles
              serik.george
              I want it to put 2 instances on the stage :
              1 with an animation
              and another with the backgroun ...

              just that the background isin't put at all...
              I used "trace" to see if it`s crashing or not and it isin`t .

              the second instance ("waypoints") doesn`t appear :(

              any help ? :(
              • 4. Re: Animation struggles
                Hampigato Level 1
                I have no idea what so ever how to help you lad. But if you really want some help, I advice you to start your own thread instead of hijacking others.
                • 5. Re: Animation struggles
                  Duckyofdoom.com
                  Okay just a little information about _root and this.

                  the this command is context sensitive, basically it refers to the object or thing your working with.

                  It's like saying him or her. Dave is a nice guy I like him.

                  If the this command doesn’t know what you're referring to its like saying. Him is good.

                  _root on the other hand refers to something specific. sceen1. Or you’re starting scene.

                  to call anything through _root, you have to know where it's located, and what it's named.

                  _root.locaton.name

                  If it's in the a frame on the main stage one it can be referred to as _root.name

                  If it's in a deeper location all the things that it's stored inside need to be listed.

                  _root.movie_clip_instance_name.movie_clip_instance_name.name

                  You seem pretty competent, so I can't imagine this is the problem. But as best I could understand your question, and just in case I thought I'd throw this out there.
                  • 6. Animation struggles
                    serik.george Level 1
                    10q....
                    Hampigato I would of made a topic but I didnt find the "Post Topic" or "New Topic" button at the time ... ( it was about 4.30 am... )