Scrolling Background in AS2 to AS3 HELP!!

Getting back in the game here - used to use AS2 for a lot of my websites and stuff - and want to get back into it, however, having issues getting used to AS3 - for example, I used this code to create neat scrolling backgrounds that moved with my mouse in AS2, but they will no longer work in AS3. How would I go about converting this code to AS3? What are the main differences and issues?

this.onMouseMove = function() {
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)

stage.addEventListener(MouseEvent.MOUSE_MOVE, constrainedMove);

var target:MovieClip = this.getChildByName("mc") as MovieClip;
var mp:Number = 8;

function constrainedMove(e:MouseEvent){
	addEventListener(Event.ENTER_FRAME, moveTarget);

function moveTarget(e:Event){
	target.x = (mouseX + target.x*mp)/(1+mp);
	if(Math.ceil(target.x) == Math.ceil(mouseX))
		trace("removed listener");

Edit: Added a working CS5 file with mc and all.
test.fla (7.6 KB)

1 Like

You are a SCHOLAR and a Gentleman!
I had actually already muddle through and figured out a way on my own, but I think this is actually going to work better- mine’s pretty jittery.
I’ll post what I came up with too to compare - thanks again!!