I. Lucky Draw
Flash provides some keyboard operations, import flash. UI. keyboard; this package provides keyboard operations,
For keyboard interaction, first import
Import flash. display. Sprite;
Import flash. Events .*;
Import flash. UI. keyboard;
- Program code:
- Public class telephone extends Sprite
- {
- Public Function telephone ()
- {
- Addeventlistener (keyboardevent. key_down, keydown); // keyboard listener
- }
- Private function keydown (Event: keyboardevent): void
- {
- Switch (event. keycode)
- {
- Case keyboard. Enter:
- // Start
- Break;
- Case keyboard. Space:
- // Pause
- Break;
- .........................
- ..............................
- ........................................ .. // Set another keyboard as follows
- }
- }
- }
Okay, this basic model has been set up. Next, we will add the functions we need in it. If we do a lucky draw, how can we pause the number rolling and so on?
2. Add a keyboard operation key
As needed, we can freely combine the keyboard locations we need, including common carriage return, space, R, P, and other setting keys.
Switch ()
{
Case keyboard value 1:
Break;
Case keyboard value 2:
Break;
}
3. Let the numbers move
How can numbers be moved? A simple idea is to use the math. Random () function to randomly retrieve a value of the array length, and then combine it with a listener to generate a numerical change for each frame;
Private var showmsg: textfield;
Private var telnumber: array = new array ();
- Stage. addeventlistener (event. enter_frame, run );
- Private function run (E: Event): void
- {Var num: Int = math. Round (math. Random () * telnumber. Length); // randomly select an integer
- Trace (Num );
- Showmsg. Text = string (telnumber [num]); // display in text
- }
Resolution: telnumber is an array
Math. Round (math. Random () * telnumber. Length); // select an integer randomly.
In this way, the integer of the array length can be obtained.
Such a mobile phone number comes out.