if ... else mouse follow help.
Hi, I'm using this code for a movie to follow mouse and nest when it leaves the stage. The movie is a hand and I need it to be a left hand on the left of the stage then nest while the right hand becomes active on the other side. Any help would be gratefully appreciated.
var targetX:Number;
var targetY:Number;
var sp:Sprite = new Sprite();
with(sp.graphics){
beginFill(0x000000);
drawRect(0,0,stage.stageWidth,stage.stageHeight);
endFill();
}
addChild(sp);
sp.alpha = 0;
sp.addEventListener(MouseEvent.MOUSE_MOVE,updateTargetF)
stage.addEventListener(Event.MOUSE_LEAVE,nestF);
function updateTargetF(e:MouseEvent) {
targetX=mouseX;
targetY=mouseY;
trace(targetX);
}
function nestF(e:Event) {
targetX=150;
targetY=700;
}
stage.addEventListener(Event.ENTER_FRAME,followBall);
function followBall(event:Event):void {
var dx:int = hand_mc.x - targetX;
var dy:int = hand_mc.y - targetY;
hand_mc.x -= dx / 5;
hand_mc.y -= dy /5;
}
It's just code I've adapted, I don't know enough actionscript to write from scratch unfortunately.
It works fine so far but I need the movie that follows the mouse to change depending on whether its on the left or right of the stage and send the original image to nest, kind of like this: http://solutions.3m.com/wps/portal/3M/en_US/3M-Technologies/Home/
Many thanks for your help
Consider this your opportunity to learn some Actionscript and take a shot at solving it.
For starters, realize that you need to be in control of both hands at the same time, so both of them need to have their own "targetX" and "targetY" properties that you continuously direct them to - One gets directed to a fixed location (its nesting position) and the other follows the mouse. So start off by having sets of code for each.
Then think about what role mouseX/mouseY play in determining whether to have the left hand or the right hand following the mouse and create the code for it... at what values should the shift of control occur... add the code in and try things until it works.
The MOUSE_LEAVE listener/handler role will need to be changed to apply nesting to both.
North America
Europe, Middle East and Africa
Asia Pacific