PDA

View Full Version : Coordinates of mc on stage



marty177
July 22nd, 2005, 12:45 AM
I can't believe I can't figure this out! What I need is really simple, but I am obviously doing it wrong.

I have a whole stack of tile instances arranged in a grid on the stage. Each mc has a button in it. All I want is when the user clicks the 'mc', to return the coordinates of that mc relative to the main stage. I've tried _root, _parent ... everything.

Does each tile have to be named? Of course I have been able to find the coordinate if I name them all but I'm dealing with about 600 of them. Also, they are arranged in a weird way that I can't use AS to generate it at runtime. Check out the attachment and you will see what I mean.

Thanks a million for any help.

Marty

mpelland
July 22nd, 2005, 08:56 AM
i would definately give each one a name, and try to make them with actionscript.

stringy
July 22nd, 2005, 10:54 AM
i would definately give each one a name, and try to make them with actionscript.

I agree with mpelland but maybe something like this might work



for (var obj in this) {
if (typeof (this[obj]) == "movieclip") {
for (var buts in this[obj]) {
if (this[obj][buts] instanceof Button) {
this[obj][buts].onPress = mypress;
}
}
}
}
function mypress() {
trace(this._parent._x+" "+this._parent._y);
}

if you decide you want to attach dynamically, its not so difficult to do this sort of pattern.Just create a grid as normal,push into an array, then use hitTest to remove the mcs you don`t want and splice from the array.