Converting Object Names to Strings in AS2

262 views Asked by At

So i've made an object called "potato", then started a loop to check if something in "_level0" has the name of "_level0.potato". What i think is that since the the things in _level0 are objects instead of strings, the object name can't be recognized as a string, so im guessing i need to find a way to convert the object name to a string or vice versa.

var potato:MovieClip = this.createEmptyMovieClip("potato", this.getNextHighestDepth());
for(objects in _level0){
trace(_level0[objects])
    if(_root[objects] == "_level0.potato"){
        trace("OMG, i found a potato on level0")
    }
}
1

There are 1 answers

0
Aspiro On BEST ANSWER

Your suggestion that the objects are stored as a string is incorrect. If you try using typeof before your

trace(typeof _level0[objects])

you will see that its type is movieclip and your "_level0.potato" is string They will not be equal. But you can convert object reference to string using String(...) construct.

And about names. You're confusing names and references. MovieClip object like some others in ac2 have property called _name. In this property name of object is stored like string. But only name, not the full path to its destination. For your potato mc _name will be equal "potato" So you could do your search like this

var potato:MovieClip = this.createEmptyMovieClip("potato",this.getNextHighestDepth());
for(objects in _level0){
trace(_level0[objects])
    if(_root[objects]._name == "potato"){
        trace("OMG, i found a potato on level0")
    }
}