Hi,
I’ve never used classes in AS2 before, however I thought it’d be worth trying. Anyway, this is the class:
class Unit {
/********************************
** CLASS VARIABLES
********************************/
private var clip:MovieClip;
/********************************
** CONSTRUCTOR
********************************/
public function Unit(scope:Object, shape) {
var n:String = ranGen(20);
while(scope[n]){
var n:String = ranGen(20);
}
clip = scope.createEmptyMovieClip(n, scope.getNextHighestDepth());
if(typeof(shape) == "string"){
clip.attachMovie(shape, shape, clip.getNextHighestDepth());
} else {
drawArray(shape);
}
}
/********************************
** SET FUNCTIONS
********************************/
// Set currentframe
public function setFrame(frame:Number):Void {
trace(clip + ".gotoAndStop( " +frame+ " )");
clip.gotoAndStop(frame);
}
// Set Y pos
public function setY(y:Number):Void {
clip._y = y;
}
// Set X pos
public function setX(x:Number):Void {
clip._x = x;
}
/********************************
** PRIVATE FUNCTIONS
********************************/
private function drawArray(arr:Array, opt:Object):Void {
trace(arr);
(opt)? clip.lineStyle(opt.thick, opt.rgb, opt.alpha) : clip.lineStyle(1, 0x000000, 100);
clip.moveTo(arr[0].x, arr[0].y);
for(var i:Number = 1;i<arr.length;i++){
clip.lineTo(arr*.x, arr*.y);
}
}
private function ran(high:Number, low:Number):Number {
return Math.floor(Math.random() * (high - low)) + low;
}
private function ranGen(len:Number):String {
var str:String = "";
for(var i:Number = 0;i<len;i++){
str += chr(ran(120, 100));
}
return str;
}
}
And the fla:
var objects:Array = [];
var map:Array = [
[1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1]
];
function compileMap(map:Array):Void {
for(var i:Number = 0;i<map.length;i++){
for(var j:Number = 0;j<map*.length;j++){
var objNum:Number = objects.push(new Unit(_root, "mBlock")) - 1;
objects[objNum].setFrame(map*[j]);
objects[objNum].setX(j * 20);
objects[objNum].setY(i * 20);
}
}
}
compileMap(map);
The above produces what I want, 9x9 squares placed in the correct order, however, the following line: “objects[objNum].setFrame(map[j]);*” does not work, it does NOT goto the correct frame (Actually it doesn’t even go to any frame), and I’ve got no idea why ._., anyone care to help me out?
Thanks in advance.