Resolved
Printable View
Resolved
I don't have any their source code, but I threw something together hopefully give you an idea of what is needed. You can probably smooth out the animation by tweaking it a little, but it is just an example. I created it in CS5 using AS 3.0, but if you don't have that version, then just copy the code below and paste it into a new file. It should still work regardless of the version. Hope this helps.
actionscript Code:import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
//Get the initial position of the mobile menu
var initX:Number = stage.mouseX;
var initY:Number = stage.mouseY;
var moveSpeed:int = 1;
var diffX:Number;
var diffY:Number;
var menuTweenX:Tween;
var menuTweenY:Tween;
var menuBox:Sprite;
//Create a stage item
menuBox = new Sprite();
var box:Shape = new Shape();
box.graphics.lineStyle(1, 0x0000FF);
box.graphics.beginFill(0x0000FF);
box.graphics.drawRect(0,0,485,250);
box.graphics.endFill();
menuBox.addChild(box);
menuBox.x = 35.95;
menuBox.y = 67;
addChild(menuBox);
//Stay alert for the mouse to move - when it does, then move the mobile menu
stage.addEventListener(MouseEvent.MOUSE_MOVE, itMoved);
function itMoved(me:MouseEvent):void
{
//HA HA, I got you now, you've move, so I'm moving
diffX = initX - stage.mouseX;
diffY = initY - stage.mouseY;
//Adjust the menu's position
moveMenu();
}
function moveMenu():void
{
//Stop the previous tween now.
try
{
menuTweenX.stop();
menuTweenY.stop();
}catch(e:Error){}
//Initialize a new tween based on the new position
menuTweenX = new Tween(menuBox, "x", Strong.easeOut, menuBox.x, diffX, moveSpeed, false);
menuTweenY = new Tween(menuBox, "y", Strong.easeOut, menuBox.y, diffY, moveSpeed, false);
menuTweenX.addEventListener(TweenEvent.MOTION_CHANGE, checkBoxPosition);
menuTweenY.addEventListener(TweenEvent.MOTION_CHANGE, checkBoxPosition);
}
function checkBoxPosition(te:TweenEvent):void
{
if(menuBox.x < 0 || (menuBox.x + menuBox.width) > stage.stageWidth)
{
menuTweenX.stop();
if(menuBox.x < 0)
menuBox.x = 0;
else
menuBox.x = stage.stageWidth - menuBox.width;
}
if(menuBox.y < 0 || (menuBox.y + menuBox.height) > stage.stageHeight)
{
menuTweenY.stop();
if(menuBox.y < 0)
menuBox.y = 0;
else
menuBox.y = stage.stageHeight - menuBox.height;
}
}
Thanks so Much! that's what I was looking for. Yea I'm going to try and get the delayed follow with the easing behind it. My code gets messy so if you have any tips for that it would be great. But thanks for taking the time to help!
Not sure what the delayed follow part you are talking about.
Yea, sorry for the vagueness. I was going to see if I could get the motion to ease in more instead of being so tight. Almost settle in. I'm not so sure about the delay but I was going to look in to trying to make the background lag just a little bit behind the mouse.
That may be possible with an ease in and ease out, or maybe a timer that waits until a specific delay before moving, or something like that.