I'll move this thread to the Flash forum in a couple of days, but as Pops is a new member I'll leave it here at present.
In frame1 put the following code:
Code:
var distance:Number = 2;
this.createTextField("display_txt", 999, 0, 0, 100, 20);
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(Key.LEFT)) {
if (sel=="ball1") {
ball1_mc._x = Math.max(ball1_mc._x - distance, 0);
} else if (sel=="ball2") {
ball2_mc._x = Math.max(ball2_mc._x - distance, 0);
} else if (sel=="ball3") {
ball3_mc._x = Math.max(ball3_mc._x - distance, 0);
}
display_txt.text = "Left";
} else if (Key.isDown(Key.RIGHT)) {
if (sel=="ball1") {
ball1_mc._x = Math.max(ball1_mc._x + distance, 0);
} else if (sel=="ball2") {
ball2_mc._x = Math.max(ball2_mc._x + distance, 0);
} else if (sel=="ball3") {
ball3_mc._x = Math.max(ball3_mc._x + distance, 0);
}
display_txt.text = "Right";
}
}
Key.addListener(keyListener);
for each MC give them the following code and instance names:
Code:
on (press) {
_root.sel="ball3"
}
That will work fine. Test it below. Click on a ball and use the left right keys.
Bookmarks