Interesting Tutorial: initialization of playbooks and objects

Source: Internet
Author: User

The sample code is written in Chinese. I don't know if you are familiar with it? I wanted to look up the word overlord and get a few e-scripts, but I was afraid that the words would not be satisfactory ~ Sorry

I was a circus, and the director asked me to schedule a show tonight. The requirement is that the first actor should first make an opening remark, and then the actor should make an introduction to "Who am I and who. I quickly made the following arrangement:

---- Actors. ----

Class actors {static var actors: Number = 50; var _ popularity: String = "bowl"; var _ name: String; function actors (name) {_ name = Name; actors. opening Speech (); self-introduction ();} static function opening speech () {trace ("Welcome to 'viveart-flash' code Park, this park has" + actors. the number of actors + a strong lineup with a little flash! ");} Function self-introduction () {trace (" now by me "+ _ popularity + _ name +" to show you the program, please give me a round of applause, OK? What? I did not hear it! More enthusiastic! ");}}

Then, I started rehearsals:
---- Performance. fla ----
(Note: code on the first frame)

Var wiyi = new actor ("Wei Yi -- Flash"); var lz = new actor ("Lao Zhang"); var xl = new actor ("Xiao Li ");

The rehearsal (in fact, the "test") results are very bad. I mentioned the previous article "Welcome prawns" and so on, later, I went back to "Welcome prawns" again ~

Needless to say, I was severely criticized by the head of the team. After carefully checking the program, I found that the error occurred in this sentence:

Function actor (name) {_name = Name; actor. Opening Speech (); self-introduction ();}

Here, the "actor. Opening Speech" should have been an execution method. Because it is put into the constructor, every time an actor comes up, it will be a bit cool. But where should I put it? In this case:

// Some code is omitted here. Please refer to the above actor. Opening Speech (); function actor (name) {_name = Name; self-introduction ();}

As a result, I became angry and warned me:
"Row 5th: This statement is not allowed in the class definition.
Actor. Opening Speech ();"
I was in a hurry and shouted, "Good! I don't care! Now I will remove it from the program! Let me give you a welcome speech! "
This will be the case for every performance in the future:
--- Performance. fla ---
(Note: code on the first release)

Actor. Opening Speech (); // God, help me! I am afraid I forgot to give my opening speech for a moment ~~ Var wiyi = new actor ("Wei Yi -- Flash"); var lz = new actor ("Lao Zhang "); var xl = new actor ("Xiao Li ");......

One day, I forgot to give my opening speech, and I was scolded by the head of the group, so that I could itch the monkey! Hurt your self-esteem ~ I don't believe I can't handle this actor program! This is the result of another effort:

Class actors {static var actors: Number = 50; // initialize class variables. static var _ opening speech: Boolean = actor. opening Speech (); // initialization class variables are actually equivalent to execution class methods. var _ popularity: String = "bowl"; // sets the default value of the 'popularity 'attribute of the object. var _ name: String; // declare the 'name' attribute of the object. function actor (name) {_ name = Name; // name attribute of the initialization object. self-introduction (); // method of executing objects .} static function opening speech () {// class method trace ("Welcome to 'viveart-flash' code Park, this park has" + actors. the number of actors + a strong lineup with a little flash! ");} Function self-introduction () {// object method trace (" now by me "+ _ popularity + _ name +" to show you the program. Please give me a round of applause, OK? What? I did not hear it! More enthusiastic! ");}}

According to this actor program, rehearse again:
--- Performance. fla ---

Var wiyi = new actor ("Wei Yi -- Flash"); var lz = new actor ("Lao Zhang "); var xl = new actor ("Xiao Li ");......

Rehearsal results show:
Welcome to the 'yiyi-flash' code Park, which has a strong lineup of 50 little flashes!
Now I'm going to give you a show in Flash. Could you give me some applause? What? I did not hear it! More enthusiastic!
Now, let me show you a large bowl of Old Zhang. Please give me some applause, OK? What? I did not hear it! More enthusiastic!
Now, I will give you a big bowl of Xiao Li performances. Please give me some applause, OK? What? I did not hear it! More enthusiastic!

Haha! Success! As for the reason for the success, I gave a detailed comment in the final actor. as. Let's take a look! Pay special attention to this sentence:

Static var _ opening speech: Boolean = actor. Opening Speech ();

This is the way to initialize the execution method! Please kindly advise and correct me!

Download the source file (change the name to "actor. as" after the download)

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.