Monday, December 28, 2009

In Flash does anyone know the actionscript to make a mask follow the x and y postion of the mouse?

This is hard. i can get the mask to foll over the mouse but it only works if you hover over the mask first. I want it to follow the mouse as soon as the mouse enters the stage.In Flash does anyone know the actionscript to make a mask follow the x and y postion of the mouse?
Try this code





//AS3





stage.frameRate = 30;





var yourMC:MovieClip = new MovieClip();


yourMC.graphics.beginFill(0x000000,1);


yourMC.graphics.drawCircle(0,0,30);


yourMC.graphics.endFill();


addChild(yourMC);





stage.addEventListener ( MouseEvent.MOUSE_MOVE, mouseMoveListener);





function mouseMoveListener(IN_Event: MouseEvent ) : void{


yourMC.x=mouseX;


yourMC.y=mouseY;





}





Ragards





Anil





anilkumarnd@gmail.com


http://flash-workshop.blogspot.com/In Flash does anyone know the actionscript to make a mask follow the x and y postion of the mouse?
For AS2 use _root._xmouse and _root._ymouse properties to set the _x and _y coordinates of your mask.





Assuming your mask is a movie clip on the root timeline, you could use the following function to make your mask follow the mouse postion. You man need to add a variable with an offset depending on exactly what your are going for.


function followMouse():Void {


mask_mc.onEnterFrame = function() {


this._x = _root._xmouse;


this._y = _root._ymouse;


}


}





Put that function on the first frame of the root timeline and then call the function from there or wherever you want the process to start. If on the root timeline use


followMouse();





For AS3, I believe it is now mouseX and mouseY

No comments:

Post a Comment