PDA

View Full Version : MC instance names inside an Array


ryanhamilton
03-05-2008, 09:25 AM
Aloha,

I have myself 10 movie clips which I want to put inside an array , and then position them using a forLoop. The instance names for each mc is column1, column2 . . . My code;

var columnWide:Number = Math.floor (stage.stageWidth/10);

function columnX (columnNum) {
var wide:Number = Math.floor (stage.stageWidth/10);
var position:Number = Math.floor(columnNum * wide);
return position;
}


var columns:Array = new Array [column1 , column2 , column3 , column4 , column5 , column6 , column7 , column8 , column9 , column10 ]

for ( var i = 0; i < 10; i++){
columns[i].y = 0;
columns[i].x = columnX(i);
columns[i].width = columnWide;
columns[i].height = stage.stageHeight;
}

They're neither repositioning nor or they resizing.
Gracias.

EDIT
please put code in
[ as ] [ /as ] tags (without spaces)

panel
03-05-2008, 09:34 AM
code looks ok. Check if there is correct reference inside for loop


for ( var i = 0; i < 10; i++){
trace(columns[i]) //sould be MovieClip
}

ryanhamilton
03-05-2008, 09:48 AM
ya, i think this traces correct.

[object MovieClip]
[object MovieClip]
[object MovieClip]
[object MovieClip]
[object MovieClip]
[object MovieClip]
[object MovieClip]
[object MovieClip]
[object MovieClip]
[object MovieClip]

Hugin_flight
03-05-2008, 09:58 AM
I think you forgot to setup your columnX function so that it would return a MovieClip...

function columnX (columnNum):MovieClip{
.........
}

ryanhamilton
03-05-2008, 10:02 AM
but it's just the number value I want the columnX function to return.
does that mean i should have:

function columnX (columnNum):Number{
}

ryanhamilton
03-05-2008, 10:15 AM
Ok, cool so that works but now when I add an extra array to mask each column it fudges up again. and actually the array code that worked before trying to add the mask stuff was just
var columns:Array = [] not var columns:Array = new Array []


var columnWide:Number = Math.floor (stage.stageWidth/10);

function columnX (columnNum):Number {
var wide:Number = Math.floor (stage.stageWidth/10);
var position:Number = Math.floor(columnNum * wide);
return position;
}


var columns:Array = [column1 , column2 , column3 , column4 , column5 , column6 , column7 , column8 , column9 , column10 ]

var columnsMask:Array = [columnMask1 , columnMask2 , columnMask3 , columnMask4 , columnMask5 , columnMask6 , columnMask7 , columnMask8 , columnMask9 , columnMask10 ]

for ( var i = 0; i < 10; i++){
columns[i].y = 0;
columns[i].x = columnX(i);
columns[i].width = columnWide;
columns[i].height = stage.stageHeight;
}

for ( var i = 0; i < 10; i++){
columnsMask[i].y = titleY;
columnsMask[i].x = columnX(i);
columnsMask[i].width = columnWide;
columnsMask[i].height = titleHigh;
columns[i].mask = columnsMask[i];
}

ryanhamilton
03-05-2008, 10:25 AM
Got it to work. I just put everything into the one forLoop,

or ( var i = 0; i < 10; i++){
columns[i].y = 0;
columns[i].x = columnX(i);
columns[i].width = columnWide;
columns[i].height = stage.stageHeight;
columnsMask[i].y = titleY;
columnsMask[i].x = columnX(i);
columnsMask[i].width = columnWide;
columnsMask[i].height = titleHigh;
columns[i].mask = columnsMask[i];
}