Hi there.
I wonder if anyone could help me with (i guess…) a minor issue in using prototypes. I know how to use them on a single movieclip but my problem is that I want to write a prototype that I can use with multiple movieclips stored in an array. That array must be filled with names of movieclips dynamic, because I am going to use a lot. They are named “triangle_1” and “triangle_2” and so on… (in this example I’ll stick to three instances)
not working code:
MovieClip.prototype.myProto = function() {
this._x += 1;
}
var triangleArray:Array = new Array;
for (i=0; i<3; i++) {
triangleArray* = "triangle_"+(i+1);
}
onEnterFrame = function(){
for (i=0; i<triangleArray.length; i++) {
triangleArray*.myProto();
}
}
If I don’t add names dynamic to the array, it works. But the I have to type every single movieclip myself (and the beauty of scripting is that it can do a whole lot of work for you). Working script:
MovieClip.prototype.myProto = function() {
this._x += 1;
}
var triangleArray:Array = [triangle_1,triangle_2,triangle_3];
onEnterFrame = function(){
for (i=0; i<triangleArray.length; i++) {
triangleArray*.myProto();
}
}
I guess it has something to do with the fact that all items in the array are stored as strings, rather then movieclips.
Can anyone explane me what I am doing wrong here?
Greets,
Jeroen