Hello, can anyone explain Senocular’s note about “check children” on the document class?
Tip:
This class only allows one child. If more are added, an error is thrown. Notice that the checkChildren method is also automatically called in the constructor since its possible that objects could have been added to the timeline within Flash which would have been before the added event listener was created.
[LEFT]package [COLOR=#000000]{[/COLOR]
[COLOR=#0000ff]import[/COLOR] flash.[COLOR=#000080]events[/COLOR].[COLOR=#000080]Event[/COLOR];
[COLOR=#0000ff]import[/COLOR] flash.[COLOR=#000080]display[/COLOR].[COLOR=#0000ff]MovieClip[/COLOR];
[COLOR=#0000ff]public[/COLOR] [COLOR=#000000]**class**[/COLOR] CustomDocument [COLOR=#0000ff]extends[/COLOR] [COLOR=#0000ff]MovieClip[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000ff]public[/COLOR] [COLOR=#000000]**function**[/COLOR] CustomDocument[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
addEventListener[COLOR=#000000]([/COLOR]Event.[COLOR=#000080]ADDED[/COLOR], checkChildren[COLOR=#000000])[/COLOR];
checkChildren[COLOR=#000000]([/COLOR][COLOR=#000000]**new**[/COLOR] Event[COLOR=#000000]([/COLOR][COLOR=#ff0000]"initialize"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#0000ff]private[/COLOR] [COLOR=#000000]**function**[/COLOR] checkChildren[COLOR=#000000]([/COLOR]evt:Event[COLOR=#000000])[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#808080]*// only allow one child in root*[/COLOR]
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]numChildren > [COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000ff]throw[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000]**new**[/COLOR] [COLOR=#0000ff]Error[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]"This movie can have only one child instance"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR][/LEFT]
I don’t get this…thanks!