3 Replies Latest reply on May 18, 2006 7:54 AM by tonyhigham

    Passing a variable to set a movieclip location

    Pulcinella2uk Level 1
      In frame 1 of the the movie I have defined the following:

      var cl_y=502.0;

      Elsewhere, I am running the following script:

      -- seaty is the original position of the movie clip as defined in frame 1
      var seaty = this+"_y";

      -- resets the position of the movie clip to the original position
      this._y = seaty;

      (note - I am just setting the _y position in this code in order to simplify the forum post)

      I expected that this._y = seaty; would reset the position of the movie clip to the original position as defined in frame 1. However, nothing happens.

      I have used a trace () to discover the value of seaty:
      Running trace(seaty) produces _level0.cl_y

      Please note that trace(seaty) does not equal the value of _level0.cl_y (which is what I am wanting to achieve)

      I then tried replacing:
      this._y = seaty;
      with the following:
      this._y = level0.cl_y;

      And this produces the desired result (moving the movieclip to the original position)

      Even though seaty = level0.cl_y
      why does this work:
      this._y = level0.cl_y;

      and yet this doesn't work:
      this._y = seaty;

      (I need it to work because I need to use the same function to reset the position of numerous movieclips, all with different original positions)

      Many thanks in expectation
        • 1. Re: Passing a variable to set a movieclip location
          tonyhigham
          i may be missing something, but i believe your seaty declaration should look like:
          var seaty = this._y //stores orinial _y value

          this+"_y" will just return a string reference to the movie clip. you should use the above, or if for whatever reason that doesn't work, i think what you were trying to do was this:
          var seaty = this["_y"]

          i hope this helps, let me know...
          • 2. Re: Passing a variable to set a movieclip location
            Pulcinella2uk Level 1
            var seaty = this._y
            doesn't produce the desired result.

            It produces the position of the movieclip where it is at the time the function is called.

            I am needing to reset the position of the movieclip to its original position when the function is called.

            My logic thus far has been:

            One frame 1, define a long list of variables with the following syntax:
            movieclipname_y = original y position of movieclipname;

            Within the function I need to call the original y position of the movieclipname that has called the function.

            The syntax I used was:

            var seaty = this+"_y"; -- returning the movieclipname and concatenating it with "_y"
            this._y = seaty; -- changing the position of the movieclipname with the original position of the movieclipname

            However, the problem is that seaty returns a string reference, which whilst being the same as the original position of the movieclip, is just treated as a string and not a particular position.

            Any ideas?
            • 3. Re: Passing a variable to set a movieclip location
              tonyhigham Level 1
              Pulcinella2uk, it tells me you have elected not to receive private messages.....so i'll put my reply here for now....

              what version of flash are you using? if you're using an old version, something like this might work:

              onClipEvent(load){
              var seatx = this._x
              var seaty = this._y
              }
              onClipEvent(mouseUp){ //or whichever event you're using
              this._x = seatx
              this._y = seaty
              }

              if you're using 7 or later though, then actionscript really ought to go on a frame instead of on a clip. so the above code would reside on frame 1 of your movie, and look like:
              var seatx = this._x
              var seaty = this._y

              onRelease = function(){ //or whichever event you're using
              this._x = seatx
              this._y = seaty
              }

              all that aside, if i understand your last question correctly, you're looking to establish these variables on the _root timeline, and access them later. the second code snippet above will produce the same result, but if you ever do want to access a variable based on a movieclips name in this way, you could do it like this:

              on frame 1of _root timeline:
              var c1_x=15;
              var c1_y=502.0;

              on frame 1 of clip:
              this._x = _root[this._name+"_x"]
              this._y = _root[this._name+"_y"]

              i hope that all made sense. let me know, and if you need to, send me a copy of your file so that i have a btter idea of what you're trying to accomplish