7 Replies Latest reply on Apr 15, 2011 9:40 PM by floatingworld

    I'm soooo lost in Actionscript 3.0  PLEASE HELP


      So I have not worked in flash or actionscript for a very very long time. Now I am taking a scripting class sing AS3. I have an excercise due by sunday night and I have no idea what I am doing. The excercise is as follows:


      Write the necessary ActionScript so that the butterfly avoids the mouse pointer when the pointer is within 20 pixels of the butterfly. The following requirements must be included in your code:
          •    You need to define the following variables (2 points each, 10 points total):
          ◦    To store the values: 15,40,285,185
          ◦    To store the speed of the butterfly: 5
          ◦    To store the distance, the mouse needs to be from the butterfly to affect it: 20
          ◦    To store the direction of movement in the x direction. Use 1 to indicate movement to the right and -1 to move left.
          ◦    To store the direction of movement in the y direction. Use 1 to indicate movement to downward, and -1 to move upward.
          •    You need to add a listener to detect mouse moves. (10 points)
          •    You should define a function named avoidMe to handle the behavior of the butterfly. (20 points)
          •    Within that function, you need to:
          ◦    use if statements to determine which direction to move the butterfly both vertically and horizontally and set the direction variables accordingly (20 points)
          ◦    move the butterfly by multiplying the speed and direction variables (20 points)
          ◦    keep the butterfly within the boundaries specified by the rectangle object (20 points).


      The graphics are already created and this is what I have so far  am I anywhere close to being on the right track?


      import flash.geom.Rectangle;
      var rx:Number = 15;
      var ry:Number = 40;
      var rwidth:Number = 285;
      var rheight:Number = 185;
      var rect1:Rectangle = new Rectangle(rx, ry, rwidth, rheight);
      var speed:Number = 5;
      var distance:Number = 20;
      var xVelLeft:Number = -1;
      var xVelRight:Number = 1;
      var yVelLeft:Number = -1;
      var yVelRight:Number = 1;