PDA

View Full Version : find mc with mouse x,y


jackalman2
02-12-2006, 03:34 PM
i need to be able to grab the mc instancename with the mouse location, so i can then change the mc's frame to a different frame. i have like, 200 of these on the stage, so i can't put if then else's into each mc on (rollOver).....

it will create a drawing effect in the stage with each mc being a small square emulating a gridline on the stage. i am using a listener to detect what keys are down for the color of the frame.

any help very much appreciated.... if only flash had an instanceUnderMouseLocation.onRollOver I'd be done by now, heh.

reyco1
02-12-2006, 03:49 PM
do you place the box movieclips on the stage dynamically? Because if you do, you can attach a code to it using hitTest or getBounds to achieve what you are trying to do. If you MANUALLY PLACED 200 MCs on ur stage, then you're in a mess dude :p

jackalman2
02-12-2006, 04:11 PM
I havent really placed anything yet, i did try some things but all to no avail.
so, i know how to place a instance of the movieclip into the stage, how would i then refer to it's instance once the user rollsover it and then respectively change its frame?

Xeef
02-12-2006, 04:23 PM
hi and welcome to As.Org



function B(_mc) {
_mc.beginFill(0x0000FF, 100);
_mc.lineTo(5, 0);
_mc.lineTo(5, 5);
_mc.lineTo(0, 5);
_mc.lineTo(0, 0);
_mc.endFill();
}
ROWS = 50;
COLS = 50;
Total = ROWS*COLS;
Xsize = 5;
Ysize = 5;
Space = 1;
for (a=0; a<Total; a++) {
O = _root.createEmptyMovieClip("MC"+a, a);
O._x = a%ROWS*(Xsize+Space);
O._y = int(a/ROWS)*(Ysize+Space);
B(O);
O.onRollOver = function() {
C = new Color(this);
C.setRGB(0xff0000);
};
O.onRollOut = function() {
C = new Color(this);
C.setRGB(0x0000ff);
};
}


P.S

by patied it will take a few sec to start (we drawing 2500 movieclips)
it's just an example

reyco1
02-12-2006, 04:31 PM
dude:

put a 25x25 MC in your library ready with export for AS then try this code:


MovieClip.prototype.whatsMyName = function() {
this.onRollOver = function() {
trace(this._name);
};
};
for (q=0; q<20; q++) {
this.attachMovie("box", "box"+q, this.getNextHighestDepth());
this["box"+q]._x = q%20*(25+2);
this["box"+q].whatsMyName();
}


[edit]
(sorry Xeef, did not see your post)

jackalman2
02-13-2006, 04:48 AM
yeah, that sure did get the name, but it put in into a trace (alert) instead of the script getting the instance name to change the frame. so, there's no way to pass the instance name of the movieclip under the mouse to the script to change its frame?

I'm now using dynamically attached movieclips now, by the way, and they have the box1, box2, box3 etc naming convention.

reyco1
02-13-2006, 07:00 AM
hi:

Just replace


trace(this._name);


with


this.gotoAndStop(3);

jackalman2
02-13-2006, 02:42 PM
well, that would be just the same as placing a bunch of them manually, then giving them the on(rollover) to change when the event triggers. i ended up using this on a button to start a "draw" mode, to bad it couldnt be any shorter :/


on (press){
colorkey = new Object();
colorkey.onKeyDown = function() {
if (Key.getCode() == 71) {
mousemove = new Object()
mousemove.onMouseMove = function() {
for (q=0; q<64; q++) {
if(_root["box"+q].hitTest(_root._xmouse, _root._ymouse)) {
_root["box"+q].gotoAndStop(2)
}
}
}
Mouse.addListener(mousemove)
_root.onMouseDown = function (){
Mouse.removeListener(mousemove)
}
}
}
Key.addListener(colorkey);
}