///////////////////////////////////////////////////////////////////////////////// // Copyright © 2010 W. Kowarschick // // Dieses Werk darf unter den Bedingungen der Creative Common Lizenz by-nc 3.0 de // (http://creativecommons.org/licenses/by-nc/3.0/de/) // vervielfaeltigt, verbreitet, publiziert und modifiziert werden. ///////////////////////////////////////////////////////////////////////////////// package { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import flash.events.KeyboardEvent; import flash.ui.Keyboard; public class Main extends MovieClip { ///////////////////////////////////////////////////////////////////////////// // MovieClips on the stage ///////////////////////////////////////////////////////////////////////////// public var d_input: MovieClip; public var d_butterfly_movie_blue: MovieClip; public var d_butterfly_movie_red: MovieClip; ///////////////////////////////////////////////////////////////////////////// // Constructor ///////////////////////////////////////////////////////////////////////////// public function Main() { // TFL-Text-Bug: The main MovieClip "stage" has not been initialized // when this constructor is executed. So initializatin // is done when the first frame is entered. this.addEventListener(Event.ENTER_FRAME, o_init); } ///////////////////////////////////////////////////////////////////////////// // Observer methods ///////////////////////////////////////////////////////////////////////////// private function o_init(p_event: Event): void { // The ENTER_FRAME observer must be removed after it has been // invoked for the first time! this.removeEventListener(Event.ENTER_FRAME, o_init); // Initialize the input text field. d_input.d_input_rounds.setFocus(); // Event listener: On a mouse click on the // button "buttonStart" the observer method "o_start" is invoked. d_input.d_button_start.addEventListener(MouseEvent.CLICK, o_start); // If the user releases a key, check whether is was the Enter key. this.addEventListener(KeyboardEvent.KEY_UP, o_check_enter); } private function o_check_enter(p_event: KeyboardEvent): void { // If the user has pressed the Enter key, start flying around. if (p_event.keyCode == Keyboard.ENTER) o_start(); } private function o_start(p_event: MouseEvent = null): void { // Disable further user inputs. d_input.visible = false; // Fetch the user input from the text field "d_input" // and transform it into an integer value. // Number instead of int, as a Number value may be NaN! var l_rounds_to_fly: Number = parseInt(d_input.d_input_rounds.text); // Do some integrity checks, as the user may input nonsense. if (isNaN(l_rounds_to_fly) || l_rounds_to_fly < 0) l_rounds_to_fly = 0; // Set the number of round to fly ... d_butterfly_movie_blue.roundsToFly = l_rounds_to_fly; d_butterfly_movie_red.roundsToFly = l_rounds_to_fly; // ... and start flying around! d_butterfly_movie_blue.gotoAndPlay("lbStart"); d_butterfly_movie_red.gotoAndPlay("lbStart"); } ///////////////////////////////////////////////////////////////////////////// // End of class ///////////////////////////////////////////////////////////////////////////// } }