I am trying to find a way of locating movieClips inside of a custom class, without using nested for loops, which is the way I created them across a grid. I have been searching for a long time now, knowing the answer somehow lies within typeof or instanceof, but I can’t get it to work - help!
[AS]
// thanks to http://www.robertpenner.com
MovieClip.prototype.drawRect = function(x1, y1, x2, y2) {
with (this) {
moveTo(x1, y1);
lineTo(x2, y1);
lineTo(x2, y2);
lineTo(x1, y2);
lineTo(x1, y1);
}
};
/////////Custom Grid Class
_global.GridModel = function(width, height, str, gridType) {
this.str = str;
this.gridType = gridType;
this.width = width;
this.height = height;
this.str = str;
this.board = new Array();
for (var i = 0; i<400; i += this.str) {
this.board = new Array();
for (var j = 0; j<400; j += this.str) {
this.board[j] = new Object();
this.board[j].id = ithis.height+j;
this.board[j].c = _root.attachMovie(“icon”, “icon”+this.board[j].id, this.board[j].id);
this.board[j].c._x = i;
this.board[j].c._y = j;
this.board[j].c.gridType = this.gridType;
this.board[j].c.redflag.lineStyle(0, 0xFF0000);
this.board[j].c.redflag.beginFill(0xFF0000);
this.board[j].c.redflag.drawRect(i, j, i+(this.str), j+(this.str));
this.board[j].c.redflag.endFill;
//trace(typeof this.board[j].c); // returns: movieclip
}
}
};
// starGrid, instance of GridModel
starGrid = new GridModel(Stage.width, Stage.height, 25, “star” );
ASBroadcaster.initialize(starGrid);
//movieClip method for mouse click
MovieClip.prototype.onPress = function() {
starGrid.whoClips();
};
/custom method to find instances of MC’s in starGrid
THIS IS NOT WORKING! I cannot get either the for…in, or
type of, to identify the movieClips in my starGrid object/
GridModel.prototype.whoClips = function() {
trace(starGrid instanceof GridModel);//returns: true
trace(typeof starGrid);//returns: object
for (var i in starGrid) {
if (typeof starGrid == movieclip) {
trace(starGrid*._name);
}
}
};
[/AS]