- Home
- Tutorials
- Flash
- Intermediate
- Object Movement Relative to Mouse

Page 3 of 3
Jesse Stratford
Jesse lives and works in Melbourne Australia. He is the Cofounder of http://ActionScript.org. A Flash enthusiast, teacher, author, freelancer and speaker Jesse's main focus nowadays is managing http://ActionScript.org, but he enjoys participating actively in community and the wider Flash scene when he has time.
View all articles by Jesse StratfordThese examples have all dealt with the _x (X position) only, but _y is just a easily manipulated. Our very first example showed this:
Now the circle desperately chases our mouse in both directions (vertically (y direction) and horizontally (x direction) and all I did was change the controller commands to:
if (_root._xmouse>_level0.circle._x) {
_level0.circle._x = (_level0.circle._x+10);
} else {
_level0.circle._x = (_level0.circle._x-10);
}
if (_root._ymouse>_level0.circle._y) {
_level0.circle._y = (_level0.circle._y+10);
} else {
_level0.circle._y = (_level0.circle._y-10);
}
ie. Exactly the same as the previous example, but with a duplicate cause for _y which is just the _x clause where every "_x" has been replaced by a "_y".
Good huh? And easy too no less. Many of you will want to replicate the original Yugop effect in which the further from the center of the stage you go in any direction, the faster the movie moves. This is very simply done by adapting the source above. Remember that faster movement is achieved by simply increasing the number of pixels added to or subtracted from the _x or _y property of the clip. I'll let you figure that much out yourself though. You've got to start somewhere! If you havea ny questions please post them on the forums rather than emailing me directly.
| Jesse Stratford is the Co-Master of ActionScript.org and a freelance Flash developer and teacher. He is based in Australia and enjoys all things Flash. NB: If you have comments or feedback please feel free to email me, but please do not email me Flash questions; the forums are provided for that purpose and you will get a faster answer by posting you question there. |
If you have found this tutorial helpful, I hope that you will take 30 seconds to visit The Hunger Site where, with just one click you can make a free donation of food to a starving person in a third-world country. We do not benefit financially from this action; it is purely an act of charity. |
| This tutorial is protected by International Intellectual Property Rights laws and may not be reproduced or redistributed in full or part, without the prior written consent of the author. Unauthorized reproduction of this tutorial or its contents may result in prosecution. I've worked hard on this tutorial, please don't steal it. |
Spread The Word
Related Articles
2 Responses to "Object Movement Relative to Mouse" 
|
said this on 15 Jun 2007 6:06:34 AM CST
It is nice. I am new in flash so i want this type tutorial.It is very easy to understand thats why it is more easier for us.Thank you very much.
|
|
said this on 09 Jul 2007 7:47:17 PM CST
Hey Jesse, great work explaining this...
no I see one small glinch... or atleast a solution I'm looking at... so what is the y distance reached the mouse level but not the x possition? then u see a not so smooth follow of the ball... so you get a linear atraction at some point... in other words this way.. is not the shortest path... to the (x,y) cordinates of the mouse from the (x,y) cordinates of the instance position...? |




Author/Admin)