Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
mkg14

moving object along with the mouse

Recommended Posts

Hello,

 

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 post
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 post
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.

 

testFile_gs.fla.zip

Link to post
Share on other sites

Carl, Please disregard my most recent question above. I was just able to figure out how to incorporate a timer class, which solved the problem. Thanks again for your help.

  • Like 1
Link to post
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.

×