AS object-oriented

xiaoxiao2021-03-06  112

Key: Note Learning to Express

Learn to use absolute path and relative path

Although AS is not a true object-oriented programming, it also has the concept of objects. This concept is always through the entire AS, so the understanding of the object is more important than grammar or other understandings. Go now: First, let's take a look at the path, the path is divided into two: absolute paths and relative paths. Friends who have done html should know this concept. But here I still have to explain in detail, I think it is going deep into the path, I am going to the path when I start school.

Before the path, it is necessary to talk about. Syntax: For example, here is a book on the table in the room, use. Syntax said:

Room. Table. Book

If you want to fine to the words on the page on the book, it is obviously

The room. Table. Book. Page. Word

Look, is it? I don't know how to say,. The syntax is to indicate that the object is, the front of the point is the parent thereof. If the room is the parent of the table, the child's child is a book. Still do not understand? This way, you should write it into "inside", this is

Room (inside) Table (inside) book (inside) page (inside) word

This is much easier? Now I start to say the path, which is also a description of the object, see:

Start with example. Create a flash file, then create a movick, MC named "MC", put it in the main scene, then create a button, put it in "MC", then drag it from the library, give it out, give it out, give These two elements instance naming (INSTANCE NAME, note that the instance name is not MC name): mc-> mymc button-> mybtn Now we assume that the main scene is a house, the MC is a table, but the button is a book, then how to express a house, Table, book? 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 scene. It is easy to understand right. The houses, tables, books here are "objects" we have to understand. When you find this object, you can do ways to operate the object. For example, I have to clean the house now, clean it, but the object is a house, the expression is like this:

House. Cleaning ()

If you can't express this object correctly, your cleaning will not be implemented correctly. * Description: Why is this after the cleaning ()? Because the cleaning method is not an object, in order to let Flash know this is a method, we must add (), or it will think that there is "cleaning" in the house.

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

House. Cleaning (); house. Wooden table. Corruption (); house. Glass table. Broken (); house. Desk. Book. See ();

Wait, I believe that you have no problem with "translation" as an AS code :) For example, you have to stop playing with the home scene,

_root.stop ();

To stop playing with MC,

_Root.mymc.stop ();

Now talk about relative paths. Still the above example. If you give you a command: repair the red chair inside the house. So how do you express it? Is:

House. Red chair. Repair ()

No matter where the people undergoing the order tell you, you will know which one to be repaired. But if he said: Repair you are sitting now. Red? Still blue? This will depend on which chair you are sitting. Then the relative expression is the chair I sit. Repair ();

Why don't you write this here?

House. I am sitting chair. Repair ()

This is wrong, because I am sitting in the chair, I may not be able to move the chair to the outside, then this expression is wrong, because the chair is not in the house at all. In exchange, use the Flash example. Now I want to play my MYMC in the home scene, don't play at the beginning, but stop first. So what do you have? I guess the way I may put into the frame of this MC in the main scene:

_Root.mymc.stop ();

This is right. But once the name of mymc changes, you have to change this sentence. Is there a way to change this "MC" instance name, will we be found by the same AS? Of course, the premise is that your AS must "sit on this MC". Enter the Edit state of the MC, write on the first frame of the MC Timeline

THIS.STOP ();

Here is also the keyword of flash, this this refers to this timeline in AS. No matter where you are, what is the name, I don't care, anyway, I will definitely stop. Why, because AS is "sitting on MC". If you are writing here

_root.stop ();

That is wrong. why? think carefully. This THIS is one of the keywords of the relative path. You have to understand it carefully. Another keyword is _parent. If you understand this, then _parent is not difficult to understand. Example: Which is a house (_root), table (mc_zhuozi), book (mc_shu) their relationship is (MC instance name in parentheses)

House. Table. Book _Root.mc_zhuozi.mc_shu

Write in the Timeline of MC_Zhuozi

Cleaning ();

It means cleaning the room; written in the mc_shu Timeline

Cleaning ();

It means cleaning the table. _Parent is also a parent. The _parent is the Timeline of the house, the _parent is also the Timeline of the table. The _parent is the object of the back of the point.

转载请注明原文地址:https://www.9cbs.com/read-103632.html

New Post(0)