# FMX - joysticks, cockpits and scrolling BG wont stop

**URL:** <https://forum.kirupa.com/t/fmx-joysticks-cockpits-and-scrolling-bg-wont-stop/123566>\
**Category:** Uncategorized\
**Created:** [September 24, 2004, 8:01pm UTC](https://forum.kirupa.com/t/fmx-joysticks-cockpits-and-scrolling-bg-wont-stop/123566 "2004-09-24T20:01:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![basefetish](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@basefetish](https://forum.kirupa.com/u/basefetish)\
**Post date:** [September 24, 2004, 8:01pm UTC](https://forum.kirupa.com/t/fmx-joysticks-cockpits-and-scrolling-bg-wont-stop/123566/1 "2004-09-24T20:01:32Z")

</div>

Hello all, new on this forum and it looks great, props to Kirupa for all the nice information provided to us fledgling flash users. I have a question in how to make a scrolling background with boundaries controlled by a joystick.  
THINK: flying a helicopter from a cockpit view. cockpit moves in coordination with the joystick and so does the background.

I have a joystick that controls one movie clip “dune” left and right, it also controls the background clip “BG” scrollling left, right, up and down.

my problem/question is how to make the BG stop scrolling when “dune” hits the border of it. It probably is a simple solution, but I am new to actionscript and have “butchered” this code from a scrolling starfield flash movie. right now my background keep scrolling out of view.

Would HitTest work?

here is my code, dont mind the extra junk, and any help is greatly appreciated:

// initialize variables and properties  
initx = dune.\_x;  
inity = dune.\_y;  
//  
\_root.onEnterFrame = function() {  
with (dune) {  
// move DUNE based on the positions of the joy  
\_rotation += (joy.\_x-joy.initx)/15;  
if (\_rotation\>6) {  
\_rotation=6;  
}  
if (\_rotation\<-6) {  
\_rotation=-6;  
}  
}

with (BG) {  
// move BG based on the positions of the joy  
\_x -= (joy.\_x-joy.initx)/15;  
\_y += (joy.\_y-joy.inity)/2;

//\_rotation += (joy.\_x-joy.initx)/15;  
//if (\_rotation\>6) {  
// \_rotation=6;  
//}  
//if (\_rotation\<-6) {  
// \_rotation=-6;

// loop the bg  
//if (\_x\>initx+800) {  
// \_x = initx;  
//}  
//if (\_x\<initx) {  
// \_x = initx+220;  
//}  
//if (\_y\>inity+400) {  
// \_y = inity;  
//}  
//if (\_y\<inity) {  
// \_y = inity+400;  
//}  
}  
};

Greg aka basefetish…
