Flash mobile lottery Program Design: Lucky Draw operation

Source: Internet
Author: User

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;

 

  1. Program code:
  2. Public class telephone extends Sprite
  3. {
  4. Public Function telephone ()
  5. {
  6. Addeventlistener (keyboardevent. key_down, keydown); // keyboard listener
  7. }
  8. Private function keydown (Event: keyboardevent): void
  9. {
  10. Switch (event. keycode)
  11. {
  12. Case keyboard. Enter:
  13. // Start
  14. Break;
  15. Case keyboard. Space:
  16. // Pause
  17. Break;
  18. .........................
  19. ..............................
  20. ........................................ .. // Set another keyboard as follows
  21. }
  22. }
  23. }

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 ();

  1. Stage. addeventlistener (event. enter_frame, run );
  2. Private function run (E: Event): void
  3. {Var num: Int = math. Round (math. Random () * telnumber. Length); // randomly select an integer
  4. Trace (Num );
  5. Showmsg. Text = string (telnumber [num]); // display in text
  6. }

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.