PDA

View Full Version : Making event listeners to stop movement


RM3.0
08-29-2009, 12:33 AM
function btnMoveActivate(event:MouseEvent):void
{
btnLogo.addEventListener(Event.ENTER_FRAME, btnMove);
btnMouseTracker.addEventListener(Event.ENTER_FRAME , btnMove);
}

function btnMove(event:Event):void
{
var Xpos:Number
var Xtrack:Number = btnMouseTracker.x;
var Xdif:Number = Xtrack - btnLogo.x;
var Xfriction:Number = .95;

btnMouseTracker.x = root.mouseX;
Xpos = Xtrack - (Xdif*Xfriction);
btnLogo.x = Xpos;
btnLogoMenu_mc.x = btnLogo.x - 45;

borderDetect.removeEventListener(MouseEvent.MOUSE_ OVER, btnMoveActivate);
borderDetect.addEventListener(MouseEvent.MOUSE_OUT , btnMoveDeactivate);
}

function btnMoveDeactivate(event:MouseEvent):void
{
btnMouseTracker.removeEventListener(Event.ENTER_FR AME, btnMove);
borderDetect.removeEventListener(MouseEvent.MOUSE_ OUT, btnMoveDeactivate);
borderDetect.addEventListener(MouseEvent.MOUSE_OVE R, btnMoveActivate);
}

borderDetect.addEventListener(MouseEvent.MOUSE_OVE R, btnMoveActivate);

Based on what I wrote here, I thought I would be able to make a zero alpha movie clip tracking the mouse stop when the mouse was off of a zero alpha, hit-detecting movie clip. I also thought that I could make the tracking movie clip continue to track when the mouse was back on the aforementioned hit-detecting movie clip.

However, it seems that what I wrote tracks the mouse and never stops, even upon moving away from the hit-detectnig movie clip. I figured that there was something that I wasn't seeing again, or something that I was missing, so maybe an extra pair of eyes would be able to help in this case.

Any assistance in this matter would be appreciated.

RM3.0
08-31-2009, 11:16 PM
OK, well I was able to get it to work...finally....but it seems like with each detection, the menu that's following the tracker with friction is slowly catching up with the tracker...almost to the point of being on top of it.

Here's the new code:

borderDetect.addEventListener(MouseEvent.MOUSE_OVE R, btnMoveActivate);

function btnMoveActivate(event:MouseEvent):void
{
btnLogo.addEventListener(Event.ENTER_FRAME, btnTrackerMove);
btnMouseTracker.addEventListener(Event.ENTER_FRAME , btnLogoFollow);

function btnLogoFollow()
{
var Xpos:Number
var Xtrack:Number = btnMouseTracker.x;
var Xdif:Number = Xtrack - btnLogo.x;
var Xfriction:Number = .99;

Xpos = Xtrack - (Xdif*Xfriction);
btnLogo.x = Xpos;
btnLogoMenu_mc.x = btnLogo.x - 45;
}

function btnTrackerMove(event:Event):void
{
btnMouseTracker.x = root.mouseX;

borderDetect.removeEventListener(MouseEvent.MOUSE_ OVER, btnMoveActivate);
borderDetect.addEventListener(MouseEvent.MOUSE_OUT , btnMoveDeactivate);
}

function btnMoveDeactivate(event:MouseEvent):void
{
btnLogo.removeEventListener(Event.ENTER_FRAME, btnTrackerMove);
borderDetect.removeEventListener(MouseEvent.MOUSE_ OUT, btnMoveDeactivate);
borderDetect.addEventListener(MouseEvent.MOUSE_OVE R, btnMoveActivate);
}
}

RM3.0
09-01-2009, 10:20 PM
I think I've hit a brick wall with this, so as I said before, any help or advice would be appreciated. You could even talk about sports if you wanted to...