1 Reply Latest reply on May 18, 2006 1:11 PM by Newsgroup_User

    update / replicate in AS2 ???

    Level 7
      Hi All,

      I used to use this AS1 on a movie clip to slide things around:


      onClipEvent (load) {
      POZ = new Array("0", "-430", "-860", "-1290", "-1720", "-2800", "430");
      }
      onClipEvent (enterFrame) {
      r += (rot-r)/6;
      rectan._x = r;
      }

      with this on the buttons:

      on (release) {

      rot = POZ[2];

      }


      However...
      This will not work in 8 whatever I do.
      Can someone explain 1) why not
      and 2) how I can update / replicate it in AS2

      Many thanks
      Tony

        • 1. Re: update / replicate in AS2 ???
          Level 7
          Tony,

          > I used to use this AS1 on a movie clip to slide things
          > around:

          Whew! Man, there are quite a few things wrong with this code. Let's
          step through everything so that you understand what you've written ... that
          may clear things up for you.

          onClipEvent (load) {
          POZ = new Array("0", "-430", "-860", "-1290", "-1720", "-2800", "430");
          }

          In this block, you've declared a variable, POZ, that is an instance of
          the Array class; in other words, this is an array object, and it contains
          seven elements, which are strings. This variable, POZ, is created when the
          movie clip it is attached to loads. You should use the var statement here
          (var POZ = ...).

          onClipEvent (enterFrame) {
          r += (rot-r)/6;
          rectan._x = r;
          }

          In this block, you're asking a certain set of instructions to occur
          every time the movie clip enters a frame. You reference a variable, r, that
          hasn't been declared anywhere (var r = ...). In AS1 and AS2, Flash
          automatically declares variables if you don't do it yourself. So the first
          time Flash sees r, and doesn't know what to do with it (because it doesn't
          yet exist), Flash just says, "Okay, let me make an r variable." It doesn't
          know what *kind* of variable to make (string, number, array, etc.), but it
          tries its best. Next, we encounter yet another variable, rot, that doesn't
          been declared anywhere.

          Before Flash MX 2004, such automatically delcared variables could be
          incremeneted, such as with your += operator. In Flash MX 2004, they cannot
          (you'll see r as NaN [Not a Number]) if you trace its value or examine it in
          the Debugger panel.

          This is one of the issues, definitely, AS1 or not. NaN is a special
          Number value that ... well, that isn't a number. So you can't set any
          movie clip's _x property to NaN.

          Declare your variables in the onClipEvent(load) event handler.

          on (release) {
          rot = POZ[2];
          }

          This comes closest to a declaration of the rot variable -- but remember,
          it is almost certian that the enterFrame code has already executed several
          times over. So this doesn't declare your variable, but basically just set
          its value.

          Problem here is, you're accessing the third element in your array
          (arrays start at zero, so element 2 is the third). But your array holds
          strings. You're trying to add strings into a math expression, so you should
          drop the quotation marks in your array constructor.

          Think through that a bit and see where you get.


          David
          stiller (at) quip (dot) net
          Dev essays: http://www.quip.net/blog/
          "Luck is the residue of good design."