Lingo08-parent/child

Source: Internet
Author: User

In lingo, parent and child are called parent scripts and child objects in the official documents. They are actually examples of classes and classes.

Returns me after constructing new

The child object is the self-contained of the parent script and an independent and complete instance.

The address used to differentiate instances. This address is me.

Therefore, the most important statement at the end of the constructor new of each parent script is return me.

The address of the current instance must be returned after new.

-- Parent script

Property
Myname
 

On New me, Pname

Myname = pname

Return
Me

End

 
 

Child, Sprite, movie

The script instance is somewhat different from the actual class instance.

The child object in ctor Ctor is more like an extension of the sprite and movie objects of director.

Child attaches to Sprite and movie to add more flexible features to it.

Sprite and movie also provide a list of child objects to be saved:ScriptinstancelistAndActorlist.

Image Description

Parent script is a cast member in the cast list,

Child object is the behavior or script extension (actor?) on sprite or movie ?).

Create a parent script

    • Create a movie, CTRL + N;
    • Open script window, CTRL + 0;
    • Write script;

-- Parent script

Property
Myname
 

On New me, Pname

Myname = pname

Return
Me

End

 

    • Set it to parent type in the script tag of Property inspector. Movie by default;
    • Name the script firstparent. (You can name the script into wt header and cast window)

Use to view parent

New Syntax of child:

Child name = new (script "parent name, I .e. Script Name", parameter list)

    1. Open the message window, CTRL + m;
    2. Input

Inst = new (script "firstparent", "firstchild ")

Put Inst. myname

 

    1. Output

-- "Firstchild"

 
 

Use parent in movie

    1. In the script window (CTRL + 0 0), create a new script. The default type is movie;
    2. Input

On startmovie

Inst = new (script "firstparent", "firstchild ")

Put Inst. myname & "created"

End

 

    1. Run Movie, CTRL + ALT + P;
    2. The message window output is displayed. Note that there is a space between firstchild and created. & The operator concatenates strings with spaces.

-- "Firstchild created"

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.