0 Replies Latest reply on May 30, 2007 6:56 PM by mottwsc

    Getting selected movements from timeline

    mottwsc
      I'm trying to control player movement based on what is happening in a game. I have a player that has several states (which are named frames) such as Frame 1 "normal" (no movement), Frame 4 "runOne" (first part of running motion), Frame 8 "runTwo" (second part of running motion), Frame 12 "jumpOne" (first part of jumping motion), and Frame 16 "jumpTwo" (second part of jumping motion).

      I call a function that determines what action to take (which could include movement) and also includes a loop for a delay in the player moving to the next spot while the movement is happening. After the return from the function, I set the player state back to normal (no movement);

      [portion of main script]
      testState(desiredState);
      player.gotoAndStop("normal");

      [relevant portions of function]
      testState = function(desiredState:Number):Void {

      switch(desiredState){

      case 3:
      // allow delay for "running" and allow player to move
      player.gotoAndPlay("runOne");
      for (counterOne = 1; counterOne <= 20000; counterOne++){
      } // end counterOne for loop
      break;

      } // end switch
      } // end testState function

      There are several issues:

      (1) In general, since I have several states - normal, running, jumping - how do I only allow a portion of the timeline to play in a looping fashion depending on what I want the player to do - for example, cycle through running motions one and two several times?

      (2) When case 3 is called, I expected the player to run while the loop was going, however; this change doesn't happen while the loop is going. It does happen at some point, because if I take the player.gotoAndStop("normal") statement away after I call the function, the player will continue to move. It just won't run while it is in the function. Am I doing something wrong or is there another way to accomplish this?

      (3) Is there a better way to allow a delay than using a loop - maybe there is a more resource-efficient way to do this?

      Thanks for any guidance.