Frame Rates, Slow Squishing Options and Leap Year Day experiments


 

  1. Here is the Frame 1 ActionScript 3.0 code. Note that the loop goes from frame #2 to frame #51 after the application gets started as the result of the user clicking a button. Frame #1 is only entered once when the .SWF file is loaded up.
  2. var n:Number = 0;
    var slowSquish:Number = 0;
    var theRate:Number;
    
    
    stop();
    
    
    frame_rate_txt.text = String(stage.frameRate);
    
    
    increase_btn.addEventListener(MouseEvent.CLICK, onIncreaseRateClick);
    decrease_btn.addEventListener(MouseEvent.CLICK, onDecreaseRateClick);
    
    
    play_btn.addEventListener(MouseEvent.CLICK, playBall);
    
    stop_btn.addEventListener(MouseEvent.CLICK, stopBall);
    
    
    slowSquish_btn.addEventListener(MouseEvent.CLICK, slowSq);
    
    
    function playBall(evt:MouseEvent):void {
    	  play();
    }
    
    
    function stopBall(evt:MouseEvent):void {
    	  stop();
    }
    
    
    function slowSq(evt:MouseEvent):void {
    	
    	  trace("The slowSquish value is: " + slowSquish);
    	  if (slowSquish == 1) {
    		  slowSquish = 0;
    	  } else {
    		  slowSquish = 1;                // slowSquish  =  not slowSquish;
    	  }                                  // ---------------- DOES NOT WORK!!!
    }
    
    
    function onIncreaseRateClick(evt:MouseEvent):void {
    	  stage.frameRate += 5;
    	  frame_rate_txt.text = String(stage.frameRate);
    }
    
    
    function onDecreaseRateClick(evt:MouseEvent):void {
    	  if (stage.frameRate > 5) {
    		  stage.frameRate -= 5;
    	  }
    	  frame_rate_txt.text = String(stage.frameRate);
    }
      
  3. Here is the Frame 2 code.
  4.   frame_rate_txt.text = String(stage.frameRate);
    
    
      count_txt.text = String(n++);        // <-- hard to understand
      
      Note:   count_txt.text = String(n);  // <-- works fine too! 
              n = n + 1;                   //     ... and is easier to understand.
    
  5. Here is the frame 21 code. It is for the slow squishing of the ball after the ball hits the ground.
  6. if (slowSquish == 1) {
        theRate = stage.frameRate;
        stage.frameRate = 5;
        frame_rate_txt.text = String(stage.frameRate);
    }
    
  7. Here is the frame 31 code. If slow squishing has just occured, set the stage's frame rate back to the original, probably much faster FPS (Frames Per Second) speed that was saved when we changed to 5 FPS upon entering the slow squish phase of the animation.
  8. if (slowSquish == 1) {
        stage.frameRate = theRate;
        frame_rate_txt.text = String(stage.frameRate);
    }
      
  9. Finally, here is the frame 51 single ActionScript statement. Note that Frame #2 has the frame label startBounceFrame. It is where the ball starts the 1st of 4 Motion Tweens to simulate a bouncing ball.
  10. gotoAndPlay("startBounceFrame");