Lets say I have a MovieClip called "Box", and "String" is actually 'box' just that its not a MovieClip
The problem I'm facing now is I can't use something like circle.addChild(this[String])
I've tried tracing this[Strin]==Box and the result returns true. And when I remove circle.addChild(this[String]), it does not add the Box into it. BUT, when I traced is there any new object added to circle, the amount still remains the same.
Any idea what seems to be the problem here?
If I understood you, you are trying to add a MovieClip
called (has a instance name of) String inside another MovieClip
called Box, right?
Well, you can't give the name String to an object, because String
is a class name in ActionScript 3.0
You can't name any object with any class name or protected keyword, such if
, for
, class
, Boolean
...
Those are words that ActionsScript uses globally (they are Top Level keywords).
Also, note that although you can name an object (give it an instance name of) MovieClip
, Sprite
, Loader
, Stage
and such, all theses names are used by ActionScript as class names, inside packages, that can be imported into your animation/application, and Flash will automatically import almost every one of them for you.
If you name your objects with those words you run some risks, like codes that don't work properly or don't compile at all...
As pointed by @Bosworth99 and @merv, you may note, as well, the naming conventions used by ActionScript, the UpperCamelCase and lowerCamelCase.
Classes are (by convention) written with UpperCamelCase (with the first letter capitalized), which indicates that name is a class name.
Objects are, generally, written with lowerCamelCase (with lower first letter and every new composed word with upper case), indicating that word is a object name (or another keyword, which may be reserved already).