Problem passing a string as a movie clip instance name
Hey there folks,
I thought this would be a simple one, but i am stumped. So I resulted to using this less than optimal solution, just to get it working...
if (lobby.gamemap.selectedItem.label == "Map1") map.AddMap(new Map1)
else if (lobby.gamemap.selectedItem.label == "Map2") map.AddMap(new Map2)
//Map1 and Map2 are movie clips in my fla library, with linkage Map1 and Map2
I have a lobby class, inside this is a combo box with the map choices...the problems arise when I try this prefered implementation
map.AddMap( lobby.gamemap.selectedItem.label )
//Throws Error - Type 1067: Implicit coercion of a value of type String to an unrelated type flash.display:MovieClip
i read in this post http://forums.adobe.com/message/2741961 that flash should be able to use this[string] to pass the string as movie clip instance name...so i tried
map.AddMap( this[lobby.gamemap.selectedItem.label] )
trace(this[lobby.gamemap.selectItem.label])
//This also throws an error, TypeError: Error #2007: Parameter child must be non-null.
//I also note that the trace comes back null...
I tried this, inclusion of the word 'new'
map.AddMap(new this[lobby.gamemap.selectedItem.label] )
//This throws - TypeError: Error #1007: Instantiation attempted on a non-constructor.
I also tried passing lobby.gamemap.selectedItem.label to a string, and trying all the previous situations with the string instead of the comboBox label.
..still no dice.
Haaalp
