moving object when mouse move in as3
i made a flash application but my problem is as follow i have a movie clip and i want to show it when user mouse over to any image of background and also i want same clip follow th开发者_运维知识库e mouse cursor.how to do so. Thank you
put 3 movieclip on the stage name first mc1, then mc2 annd finally mouse_mc
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends MovieClip
{
public function Main()
{
stage.addEventListener(MouseEvent.MOUSE_MOVE, _onMouseMove );
mouse_mc.mouseEnabled = false;
mc1.alpha = 0;
mc2.alpha = 0;
}
private function _onMouseMove (event:MouseEvent):void
{
if(event.target is MovieClip)
{
var target:MovieClip = (event.target as MovieClip);
if(target.alpha == 0){
target.alpha = 1;
}
//trace( (event.target as MovieClip).name );
}
// follow mouse
mouse_mc.x = mouseX;
mouse_mc.y = mouseY;
event.updateAfterEvent();
}
}
}
this will make mouse_mc follow your mouse and reveal hidden movieclip on roll over.
for a perfect follow mouse you can also use native cursor http://active.tutsplus.com/tutorials/actionscript/quick-tip-setting-a-native-cursor-using-flash-player-10-2/
enjoy
精彩评论