# Scrolling Background in AS2 to AS3 HELP!!

**URL:** https://forum.kirupa.com/t/scrolling-background-in-as2-to-as3-help/634393
**Category:** flash
**Created:** [March 26, 2016, 12:00am UTC](https://forum.kirupa.com/t/scrolling-background-in-as2-to-as3-help/634393 "2016-03-26T00:00:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![StudioNoire](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/studionoire/32/7543_2.png) [@StudioNoire](https://forum.kirupa.com/u/StudioNoire)
#### Post date: [March 26, 2016, 12:00am UTC](https://forum.kirupa.com/t/scrolling-background-in-as2-to-as3-help/634393/1 "2016-03-26T00:00:03Z")

</div>

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() {  
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));  
}  
};  
}

---

<div class="post-metadata">

### Author: ![linusj](https://avatars.discourse-cdn.com/v4/letter/l/b2d939/32.png) [@linusj](https://forum.kirupa.com/u/linusj)
#### Post date: [April 1, 2016, 7:58pm UTC](https://forum.kirupa.com/t/scrolling-background-in-as2-to-as3-help/634393/2 "2016-04-01T19:58:21Z")

</div>

```
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");
		removeEventListener(Event.ENTER_FRAME,moveTarget);
	}
}

```

Edit: Added a working CS5 file with mc and all.  
[test.fla](https://forum.kirupa.com/uploads/short-url/eFiERq6cNGdLRObyu0lQccrbmYR.fla) (7.6 KB)

---

<div class="post-metadata">

### Author: ![StudioNoire](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/studionoire/32/7543_2.png) [@StudioNoire](https://forum.kirupa.com/u/StudioNoire)
#### Post date: [April 1, 2016, 11:15pm UTC](https://forum.kirupa.com/t/scrolling-background-in-as2-to-as3-help/634393/3 "2016-04-01T23:15:15Z")

</div>

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!!
