3 Replies Latest reply on May 15, 2007 7:55 AM by crila5000

    setProperty alternative?

    crila5000
      ok here's the deal... i have some old code that worked in as2, and im trying to get it to work in as3. i think ive fixed all of the problems with it (i think), but im am stumped on how to get around the setProperty part. the button instance is oney, and the MC instance is box. here is the code...


      // code for the button and to tell the movie clip where to go
      function mouseDownHandler(event:MouseEvent):void {
      box.targXmove = 151.1;
      box.targYmove = 151.1;
      }
      oney.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

      // code to make it move
      function narnar(event):void {
      var cXmove = box.x;
      var cYmove = box.y;
      var difXmove = cXmove-box.targXmove;
      var difYmove = cYmove-box.targYmove;
      setProperty(this, x, cXmove-(difXmove/5));
      setProperty(this, y, cYmove-(difYmove/5));
      }
      box.addEventListener(event.ENTER_FRAME, narnar);


      any suggestions? (please dont say change it to AS2, i already know that works)
        • 1. Re: setProperty alternative?
          Level 7
          crila5000,

          > im am stumped on how to get around the setProperty part.

          setProperty() is older than the hills. It's just a precursor to dot
          notation, which you're already using. ;)

          For example, this ...

          box.targXmove = 151.1;

          ... is an example of dot notation. You're setting the targXmove property of
          this box movie clip to 151.1. It's the same as saying this ...

          setProperty(box, targXmove, 151.);

          ... only clunkier.

          To change a line like this ...

          setProperty(this, x, cXmove-(difXmove/5));

          ... you'd render it like this:

          this.x = cXmove-(difXmove/5);


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: setProperty alternative?
            Rothrock Level 5
            this.x=cXmove-difXmove/5;

            Please don't take this personally, but I'm always amazed that folks still use setProperty. (It went out of favor in something like 2002!) What I'm wondering is why you can set cXmove (a property) and you can get box.x (a property) and get/set box.targXmove (another property), so what was it about setting x and y that was giving you such a stumbling block?

            This question is really a serious attempt for me to try and understand how other folks think so I can explain things better.
            • 3. Re: setProperty alternative?
              crila5000 Level 1
              thanks for the help guys, you rock.

              to answer your question rothrock...

              i got this piece of code from some random tutorial site about a year ago. it worked so i did not question using the setProperty method. i just figured using that method was the only way to get the AS to solve the equation. i did not realize you can just enter the equation like you would a single number.

              also im kind of a noobie with AS thats more complicated than setting up buttons, loading bars, and other simple stuff.

              hope that cleared up my idiot-ness for you.

              thanks again for the help.