I'd like to know if there is a way to call up a frame in a flash movie by the angle of the mouse as it is possitioned from a centeral x/y possition. This is way over my head as far as coding goes, but i think i could reduce my file size and perhaps have my animation follow my mouse even when the user isn't pointing to something over the movie if I can figure out how to do this with actionscript instead of buttons.
If you want an animation to follow the mouse - create a MC, within it create an animation, make sure it centered, get back to the main stage, drag the MC you've just created into the main stage, right click on the MC, select Action and paste this script:
code:
onClipEvent (load) {
startDrag("", true);
}
Sometimes the most simple things are the most effective...
well the idea is, that I have a drawing of a girl and i have illustrated her head turning to look around 360 from the center of her face. I have one angle on each frame. And the effect is to have her looking where ever the mouse is pointing.
Right now i'm using buttons to call each frame on roll over, but i was hoping for a code that might do it based on angle/degree from the x/y of the center of her face.
Last edited by RazzberryGirl; 09-06-2003 at 06:54 PM.
I haven't tested this but it should be similar to what you want
put it into an onEnterFrame function
code:
/*************
vars -
cx = center of girl's head (x-position)
cy = center of girl's head (y-position)
dx = change in x from girl's head to mouse
dy = change in y from girl's head to mouse
rads = angle from positive x-axis to line from girl's head in radians
degs = same as rads but in degrees
frame = frame number to go to
*************/
dx = _root._xmouse - cx;
dy = _root._ymouse - cy;
// get angle
rads = Math.atan2(dy, dx);
// convert to degrees
degs = 180 / Math.PI * rads
// convert to 0-360 just in case
frame = Math.floor(degs) % 360;
I put the code yasunobu13 gave on the first frame and was able to understand it as far as the cx and cy. I extended my frames out to take up 360 frames so that there's something there for all 360 degrees when called upon by the angle of the mouse's possition in relation to the x/y center. What confuses me is the rest of the code. What does "change in x from girl's head to mouse" mean? And do I have to figure out any stuff for the rads, degs and frame? if so can you point me in the right direction? Cause I know something's wrong since it didn't work :\
/*************
vars -
cx = center of girl's head (x-position)
cy = center of girl's head (y-position)
dx = change in x from girl's head to mouse
dy = change in y from girl's head to mouse
rads = angle from positive x-axis to line from girl's head in radians
degs = same as rads but in degrees
frame = frame number to go to
*************/