Tuoren series AS getting started tutorial-Object

Source: Internet
Author: User

These tutorials are intended for beginners of Flash.More hands-on and less questions. The following tutorials are intended for readers with basic operating knowledge of Flash (MX. While viewing my tutorials, I hope I can enable Flash and do it while watching. In this way, you will be more impressed. By the way, let's see where I wrote the error :)

Although AS is not really object-oriented programming, it also has the concept of objects. This concept runs throughout the entire AS. Therefore, understanding the object is more important than understanding the syntax or others. Start now:

First, let's take a look at the path. There are two types of paths:Absolute path and relative path. Friends who have done html should know this concept. But here I still want to explain it in detail. I think the path should be understood in depth. When I was a beginner, I just hit the path.

Before speaking about the path, it is necessary to first talk about. Syntax: for example, here we want to represent a book on the table in the room, which is expressed in. Syntax:

Room. Table. Book

Obviously

Room, table, book, page, word

See it, right? I don't know how to say it. The. syntax is like this, indicating the object. The front of the vertex is the parent level after it. If the room is the parent level of the table, the child level of the table is the book.
Still do not understand? In this case, you can create "Inside" in.

Room (inside) Table (inside) Book (inside) page (inside) Words

This is much easier, right?

Now I am going to talk about the path. Here we also need to describe the mixed objects. See:

Start with the example. Create a new Flash file, create a MovieClip, name MC as "MC", put it in the main scenario, and then create a button and put it in "MC, then drag one from the database and place it in the main scenario to Name the two element instances (Instance Name, note that the Instance Name is not the MC Name ):

MC->myMC   button->myBtn

Now we assume that the main scenario is a house, MC is a table, and the button is a book. How do we express the house, table, and book respectively? As follows:

_ Root house
_ Root. myMc house. Table
_ Root. myMc. myBtn house. Table. Book

Here _ root is the keyword of Flash, indicating the Timeline of the main scenario.
It's easy to understand, right. The houses, tables, and books here are all objects we need to understand ".

Only after you find this object can you operate the object and apply methods to the object. For example, if I want to clean the house now, the cleaning method is used, but the object is the house. The expression is as follows:

House. Clean ()

If you cannot correctly express the House object, Your cleaning will not be implemented correctly.

* Note: Why add () after cleaning? Because the cleaning method is not an object, in order to let Flash know that this method is a method, we must add (), or it will think that there is a "cleaning" in the house.

Now, we can easily operate everything in the room, such

House. Clean ();
House. wooden tables. Organize ();
House. glass table. Broken ();
House. Desk. Book. Watch ();

Wait, I believe it's okay to translate them into the AS Code. For example, if you want to stop playing in the main scenario

_root.stop(); 

To stop MC playback

_root.myMc.stop();

Now let's talk about relative paths. Or the above example. Let's assume you have a command: repair the red chair in the house. So how to express it? That is:

House. red chair. Repair ()

No matter where the person giving you the Command tells you, you will know which chair you want to repair. But if he says so, fix the chair you are sitting in. Red? Or blue? It depends on which chair you are sitting in. The relative expression is

My chair. Repair ();

Why don't I write this here: House, chair I sat in, repair ()
This is wrong, because the chair I sit in is not fixed. I may move the chair out of the house to sit, so this expression is wrong, because the chair is not in the house.
Use the Flash instance description. Now I want to stop myMC in the main scenario from playing it at the beginning. So what are your solutions?
The method you guessed might be to put the MC frame in the main scenario:

_root.myMc.stop();

This is correct. But once the name of myMc changes, you have to change this sentence.
Is there a way for the "MC" Instance name to be found in the same way? Of course you can, provided that your AS must "Sit on this MC ".
Enter the editing status of Mc, and write in the first frame of Mc's Timeline

this.stop();

This is also the keyword of Flash. this refers to the Timeline in which AS is located.
Now, no matter where you put the MC and what you name it, I don't care. It will definitely stop. Why, because AS is "sitting on MC ".
If you write _ root. stop () Here, it will be wrong. Why? Think about it.
This is one of the keywords of the relative path. You must understand it carefully.
Another keyword is _ parent. If you understand this, _ parent is not hard to understand. Example:
Which of the following is the assumption House (_ root), table (mc_zhuozi), and book (mc_shu)? Their relationship is (mc Instance name in brackets)
House. Table. Book
_ Root. mc_zhuozi.mc_shu
In the timeline of mc_zhuozi, write

_ Parent. Clean ();

This means to clean the room;
Write in the timeline of mc_shu

_ Parent. Clean ();

It means cleaning the table.

_ Parent is also the parent level. The _ parent of the table is the timeline of the house, and the _ parent of the book is the timeline of the table. The _ parent of the object after the vertex is the object before the vertex.

This is the time. Let's review:

Point syntax
Learn to express objects
Learn to use absolute paths and relative paths to express objects

If you understand it, we can go into practice ..

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.