1 Reply Latest reply on May 16, 2007 3:43 PM by Newsgroup_User

    Actionscript2 problem newbie

      I am doing a project for a beginning action script
      class in school. The teacher set up this project
      using only the first two frames, w/
      the second frame,.... the gotoAndPlay(1)

      I am trying to create what looks like a
      four cylinder engine.
      So far, only the pistons, actually,
      I am still trying to get the
      piston to go up and down
      continuously on the page,

      I have one piston made in a 3d program which I just want to
      go up and down like a piston, so far I have it going up
      inside of a 400 by 600 Flash screen.
      I want this to loop going up almost to the top
      of the screen then coming down and
      stopping close to the bottom.
      I will have four pistons on the page which, hopefully
      will function like pistons in a engine .

      So far I have this,(below)
      I am thinking I might need a "stop"
      command? I am new to Action Scripting & trying to learn:

      pistOn._y = pistOn._y-30;
      pistOn._y = pistOn._y;

      if(pistOn._y == 25){
      pistOn._y = pistOn._y-30;

      //now to go back up
      else if(pistOn._y==25){
      pistOn._y = pistOn._y+30;
      I am sure this is not correct
      what I plan to do is put four pistons
      side by side, placed and
      moving like what you would see in a engine.

      Maybe add a few other things later,
      but now I am just trying to get this up and down plus
      the loop.

      here is the Flash file so far:



        • 1. Re: Actionscript2 problem newbie
          Level 7
          Hi Kevin,

          I'm guessing that you are using a version of Flash later than 5. If
          that's the case then you don't want to use a two frame movie or
          movieClip to create an animation. I hope that using two frames with the
          second frame looping back to the first, was something that you found on
          your own. Your instructor didn't give you that scenario, I hope.

          You can accomplish the whole animation in a single frame using a looping
          function. You could use something like this written to a frame action

          /* create three variables, the minimum position, the maximum and
          a boolean switch to control the direction...
          var theTop:Number = 30;
          var theBottom:Number = 0;
          var movingUp:Boolean = false;

          /* this onEnterFrame function will repeat at the frame rate.
          piston1 is the instance name of the movieClip object that you want
          to animate.
          You can write a similar function for each of the pistons. to stagger the
          movement, give each clip a different starting location and set two to
          use the boolean as true and two to false. You'll want to create 4
          boolean variables.
          piston1.onEnterFrame = function() {
          if (movingUp) {
          if (this._y < theTop) {
          this._y += 5;
          } else {
          movingUp = false;
          } else {
          if (this._y > theBottom) {
          this._y -= 5;
          } else {
          movingUp = true;

          Rob Dillon
          Adobe Community Expert