-
Follow Mouse
I need an example of code for CS3 AS3. I want to have a mc follow my mouse around the stage. Thanks!
Jay Diegar
http://www.Diegar.com - Animated Chaos!
-
One way:
PHP Code:
package {
import flash.display.MovieClip
import flash.events.MouseEvent
public class FollowDoc extends MovieClip {
//MyMC linked in the library:
private var theMC:MyMC;
public function FollowDoc():void {
theMC = new MyMC();
addChild(theMC)
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
}
private function onMove(me:MouseEvent):void {
theMC.x = this.mouseX;
theMC.y = this.mouseY;
}
}
}
I (Love | Hate) Flash.
----
Save a version back so others may help you!
-
Here is another approach. It assumes that the cursor symbol is already on the stage with the instance name "cursorInstanceName".
Following code goes into a frame.
Code:
stage.addEventListener(MouseEvent.MOUSE_MOVE, followMouse);
function followMouse(evt:MouseEvent):void {
cursorInstanceName.x = mouseX;
cursorInstanceName.y = mouseY;
}
-
If you doesn't want your mouse cursor to show during this, you can use:
Mouse.hide();
But then you have to import flash.ui.Mouse;
-
With these sort of mouse-dependant events, I also like using evt.updateAfterEvent(). Keeps things nice and close.
I (Love | Hate) Flash.
----
Save a version back so others may help you!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|