Jump to content
Search Community

moving object along with the mouse

mkg14 test
Moderator Tag

Recommended Posts



Is there a way for the viewer to control an object with his mouse? First I want the object to enter the stage and stop. After the object stops I would like the viewer to be able to move it up and down on the y axis using his mouse.


Any help would be appreciated!

Link to comment
Share on other sites

create a new fla with an MovieClip named mc and use this code:


import com.greensock.*;
import com.greensock.easing.*;
import flash.events.MouseEvent;

//start mc at top left corner
mc.x = mc.y = 0;

//move mc to 200, 200
TweenLite.to(mc, 1, {x:200, y:200, onComplete:followMouse});

//call this function onComplete of tween
function followMouse() {
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveIt);

function moveIt(e:MouseEvent):void {
TweenLite.to(mc, 0.5, {x:this.mouseX, y:this.mouseY});

Also there is a lot to learn by reading about these other approaches.

Link to comment
Share on other sites

Thank you Carl! That worked perfectly. Thanks as well for the link to other approaches.


In terms of ending the mouse event (moveIt), if the user interacts with the object I have figured out how to end it after a certain amount of time and move on to the final screen of the animation. Say, however, that the user does not interact with the object at all, but I still want to end the mouse event after a certain amount of time and move on to the final screen. Not sure how to incorporate that into the coding. (Use a timer?) Can you help? I've attached my zipped flash file. It looks super generic because I replaced the photos with simple graphic screens.



Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...