Ok, I’m making a map creator for a tabletop game. The idea is that the map creator would consist of a 48x48 grid and would allow people to drag items onto that grid and save the positional layout of objects like trees and buildings.
So I’m working on the very first steps of this and have written the script so far to dynamicaly generate a 48x48 grid and created a test object to be dragged called “follow”.
The dynamicaly generated MC draws from the “grid” MC from the library which consists of two layers; the outline of a box and an MC named “grid_bg” which contains a coloured square (set to the same size as the outline). This is all placed into the “container” MC which by default is empty.
This part I get working fine.
the “follow” mc is set so that it can be dragged on a mouse click.
Now the idea is that if a hitTest is run to see if “follow” is in contact with any of the “grid_bg” MC’s and if so, run code (i.e. hide or show the grid_bg mc).
This is where I am encountering problems. If I set the hitTest into a layer within the “grid” MC, it only runs the hit test when the movie is first loaded and ignores you dragging and dropping the “follow” mc. If the hitTest is placed into the actions of the “grid_bg” MC and used in conjuction with an IF statement, it seems to act like there is a collision on every box generated.
Any ideas?
Code is as follows:
Code to generate the grid:
//make textboxes
count=2304;
tcount=1;
ycount=1;
for(i=1;i<=count;i++){
if( tcount==49 ) {
ycount++;
tcount=1;
}
new_mc = container.attachMovie("grid", "mc_"+i, i);
new_mc._x = (10*tcount)-10;
new_mc._y = (10*ycount)-10;
tcount++;
}
Code on the “follow” MC:
on (press) {
startDrag ("_root.follow");
}
on (release) {
stopDrag ();
}
Code currently on the “grid_bg” MC (which is within the “grid” MC which gets copied into the “container” MC):
onClipEvent (enterFrame) {
if (this, hitTest(_root.follow)) {
grid_bg._visible=true;
} else {
grid_bg._visible=false;
}
}