1 Reply Latest reply on May 17, 2006 4:07 AM by blemmo

    Resizing an instance using AS

    AESS1981 Level 1
      I want to resize the height of a rectangle to a random size between 0 and 200 pixels every half a second.
      Is this possible - does anyone have any advice or tutorials on wher to start...?

        • 1. Re: Resizing an instance using AS
          blemmo Level 1
          Check out Math.random() and setInterval(), that's all you need. With setInterval, you can call a function repeatedly, so you'll need a function that changes the rectangle. e.g.:
          function changeRect(rect){
          rect._height = Math.random()*200;

          Because Math.random() returns a random number between 0 and 1, it has to be multiplied by 200 to return numbers between 0 and 200. Check the Help, there's another (better) example for random numbers in certain intervals.

          Then you just have to set the interval to call this function in the frequency you wish:
          var intervalID = setInterval(changeRect, 500, rect_instance);

          500 ms = half a second, rect_instance = the instance of the rectangle. If that is always the same instance, you can also avoid this parameter and put the name in the changeRect function.

          To stop the interval, use