rank noob here, so i’m sure you all can point out in a second what i’m doing wrong…
situation: i have an mc on the stage and i need to know the mouse’s coordinates over that mc. i rigged up a test based on a script from one of MM’s help files.
- create a new flash document
- draw a rectangle or whatever on the stage then make it a movie clip
- delete the instance on the stage and export the new mc for actionscript under the linkage identifier “mov1”
- cut and paste this code into the Actions panel for the first frame of the main timeline:
// set up the text field that reports the mouse position on all the movieclips (including itself)
this.createTextField("mouse_txt", this.getNextHighestDepth(), 0, 0, 150, 100);
// this requires a movie clip in the library linked as "mov1" (it's called black because mine was a black rectangle)
this.attachMovie("mov1", "black", this.getNextHighestDepth());
// set up an empty movie clip that will be just to the right of the text field
this.createEmptyMovieClip("my_mc", this.getNextHighestDepth());
// set up an inverted movie clip just under black
this.attachMovie("mov1", "rot", this.getNextHighestDepth());
// spread the movie clips around
black._x = 0;
black._y = 100;
rot._x = rot._width;
rot._y = 100 + rot._height*2;
rot._rotation = 180;
my_mc._x = 150;
my_mc._y = 0;
my_mc._width = 100; // just for the heck of it give it some dimension
my_mc._height = 66;
// set up the display on the text field
mouse_txt.html = true;
mouse_txt.backgroundColor = 0xFF0000;
mouse_txt.background = true;
mouse_txt.multiline = true;
var row1_str:String = " <b>_xmouse </b><b>_ymouse</b>";
// every time the mouse moves, report its new position
my_mc.onMouseMove = function() {
mouse_txt.htmlText = "<textformat tabStops='[50,100]'>";
mouse_txt.htmlText += row1_str;
mouse_txt.htmlText += "<b>_level0</b> "+_xmouse+" "+_ymouse;
// the position of the mouse on the stage
mouse_txt.htmlText += "<b>text</b> "+mouse_txt._xmouse+" "+mouse_txt._ymouse;
// the position of the mouse on the text field
mouse_txt.htmlText += "<b>my_mc</b> "+my_mc._xmouse+" "+my_mc._ymouse;
// the position of the mouse on the empty clip
mouse_txt.htmlText += "<b>black</b> "+black._xmouse+" "+black._ymouse;
// the position of the mouse on the clip from the library
mouse_txt.htmlText += "<b>rot</b> "+rot._xmouse+" "+rot._ymouse;
// the position of the mouse on the rotated clip
mouse_txt.htmlText += "</textformat>";
};
What i notice is that the coordinates return correctly for all of the movie clips (including the one rotated by 180 degrees!) except the empty one, which seems to multiply what its coordinates would be by about 16000. Also, sometimes the cursor position isn’t a pixel value! Are these bugs in flash or what? Does anyone know how to fix them in a way that isn’t just hardcoding a division by 16000?