04 | 23 :: flash fun
Here is a little tidbit, which i was unable to find on the web, under any search terms that seemed reasonable to me.
in flash, if you have the string name of an instance, and you want to access that instance, you use the eval funtion and the string to call it up [eval(string) returns a reference to the instance].
So say, that i wanted to create an array of dynamically loaded clips, well then i attach them to the movie, and then populate the array with eval(name). hmm this might be less confusing if i show you what i am doing. I won't muddle up the front page with the code, so click to read more.
So to make it so you can treat your symbols in your library like regular class objects in the actionscript, you have to jump through some hoops.
//letterD
//This is the constructor, with one class variable.
function letterD() {
color=new Array(255,255,255);
}
//Then we need to tell flash that it gets
//all the movieclip properties
letterD.prototype = new MovieClip();
//A class function
letterD.prototype.setColor = function (newColor) {
//unifinished
};
//finally we have to register it so that we can actually do
//something with it. the only non-obvious part is that you
//have to set the linkage of the symbol to export for action
//script, with an apporpriate name, in this case my export
//name and class name are the same.
Object.registerClass( "letterD" , letterD );
Once you have created the class, you can now attach a new instance of the symbol to your movie
attachMovie("letterD","da",90);so now, we have a new instance, and we want to do something with it, so we have to get a hold of the instance, which is where eval comes in
var sym = eval("da");
//now you can treat it like a regular movie clip
sym._y += 20;
...