-
Convert scrolling background from AS2 to AS3
Just getting back into flash development here and slowly learning AS3.
I had a great effect on an old website of mine that I used often of a scrolling background that moved with your mouse.
This is the coding I came up with years ago to get it to work - the background movie was called 'BackGroundBar' -
Anyway, any idea how I would even remotely start converting this to AS3?
Any help would be appreciated, thanks.
this.onMouseMove = function() {
constrainedMove(BackGroundBar,4,1);
};
function constrainedMove(target:MovieClip, speed:Number, dir:Number) {
var mousePercent:Number = _xmouse/Stage.width;
var mSpeed:Number;
if (dir ==0) {
mSpeed = 1-mousePercent;
} else {
mSpeed = mousePercent;
}
target.destX = Math.round(-((target._width-Stage.width)*mSpeed));
target.onEnterFrame = function() {
if (target._x == target.destX) {
delete target.onEnterFrame;
} else {
target._x += Math.ceil((target.destX-target._x)*(speed/100));
}
};
}
-
.
Hi,
Maybe this might give you some help, it's CS5 low as I can go.
Mess around with it, there is probably a better way too.
PHP Code:
import flash.events.Event;
stage.addEventListener(MouseEvent.MOUSE_MOVE,constrainedMove(BackGroundBar,4,1));
function constrainedMove(target:MovieClip, speed:Number, dir:Number):Function
{
return function(e:MouseEvent):void
{
var mousePercent:Number = mouseX / stage.stageWidth;
var mSpeed:Number;
if (dir == 0)
{
mSpeed = 1 - mousePercent;
}
else
{
mSpeed = mousePercent;
}
target.x = Math.round( - ( (target.width - stage.stageWidth) * mSpeed) );
target.addEventListener(Event.ENTER_FRAME,doMove);
function doMove(e:Event):void
{
if (target.x == target.x)
{
target.removeEventListener(Event.ENTER_FRAME,doMove);
}
else
{
target.x += Math.ceil( (target.x - target.x) * (speed / 100) );
}
}
};
}
-
.
Hi,
You could also do it like so without passing the vars direct to the function, however I'm not sure where you a rwe getting the target.destX value from.
PHP Code:
import flash.events.Event;
import flash.display.MovieClip;
var target:MovieClip = BackGroundBar;
var speed:Number = 4;
var dir:Number = 1;
var mousePercent:Number;
var mSpeed:Number;
stage.addEventListener(MouseEvent.MOUSE_MOVE,constrainedMove);
function constrainedMove(e:MouseEvent):void
{
mousePercent = mouseX / stage.stageWidth;
if (dir == 0)
{
mSpeed = 1 - mousePercent;
}
else
{
mSpeed = mousePercent;
}
target.x = Math.round( - ( (target.width - stage.stageWidth) * mSpeed ) );
target.addEventListener(Event.ENTER_FRAME,doMove);
}
function doMove(e:Event):void
{
if (target.x == target.destX)
{
target.removeEventListener(Event.ENTER_FRAME,doMove);
}
else
{
target.x += Math.ceil( (target.destX - target.x) * (speed / 100) );
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|