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)
- Open the message window, CTRL + m;
- Input
Inst = new (script "firstparent", "firstchild ")
Put Inst. myname
- Output
-- "Firstchild"
Use parent in movie
- In the script window (CTRL + 0 0), create a new script. The default type is movie;
- Input
On startmovie
Inst = new (script "firstparent", "firstchild ")
Put Inst. myname & "created"
End
- Run Movie, CTRL + ALT + P;
- The message window output is displayed. Note that there is a space between firstchild and created. & The operator concatenates strings with spaces.
-- "Firstchild created"