Copy link to clipboard
Copied
I followed this tutorial to place my movie clips into grid positions. Each movie clip contains a text with their respective numbers. I want to be able to determine which movie clips are on the leftmost and rightmost column using an if statement. I was able to determine the top, bottom, and corner movie clips but I can't figure out how to check for leftmost and rightmost. In this example, movie clips 4 and 7 are leftmost while 6 and 9 are rightmost but I need a code to determine the leftmost and rightmost even when the number of movie clips in the grid are changed. I hope my explanation is clear enough. I would appreciate any help. Thank you.
Here's the code i have:
var tileCount:int = 12;
var rowCount:int = 4;
var colCount:int = tileCount/rowCount;
var col:int = 0;
var row:int = 0;
var space:Number = 2;
for (var i:int = 0; i < tileCount; i++){
col = i % colCount;
row = int(i/colCount);
var mc:MovieClip = new box();
mc.txt.text = i+1;
mc.x = (mc.width + space) * col;
mc.y = (mc.height + space) * row;
addChild(mc);
if ((mc.txt.text == rowCount/rowCount)||(mc.txt.text == colCount)||(mc.txt.text == tileCount-colCount+1)||(mc.txt.text == tileCount)){
mc.gotoAndStop("corner");
}else if ((mc.txt.text < colCount) && (mc.txt.text > 1)){
mc.gotoAndStop("topEdge");
}else if ((mc.txt.text < tileCount) && (mc.txt.text > tileCount-colCount+1)){
mc.gotoAndStop("bottomEdge");
}
}
Copy link to clipboard
Copied
if you only need that info when tiles are created, use the x and y properties. (and you have a typo, rowCount/rowCount.)
Copy link to clipboard
Copied
What I'm actually trying to do is make it so that whenever I drag and drop the tiles close enough to each other I will know if the tiles are in order. These tiles are supposed to be movable. Which is why I needed to know the position of each relative to each other. I actually figured it out though. Instead of numbering them 1, 2, 3, etc. I numbered them according to their places in row and column. So the for a 9x9 grid, the numbering goes 11, 12, 13, for the first row, then 21, 22, 23 for the second, then 31, 32, 33 for the third. So I'll just check inside each movie clip whether the numbers in the textbox matched. Thanks for helping anyway.
I probably should have given it more thought and time before asking on here, I was just getting a bit frustrated. I'm not really good at math and I thought what I was trying to do will require some sort of equation I didn't know how to do so I decided to ask for help.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now