hey, im trying to pan a movieclip around my stage, in both x and y, depending on mouse location. i based the code for this on the tutorial found here.
the movieclip im working with is 1100x900 and the stage is 800x600.
public function constrainedMove(target:MovieClip, speed:Number, dir:Number):void {
var mousePercentX:Number = this.mouseX/800;
var mSpeedX:Number;
if (dir == 1) {
mSpeedX = 1-mousePercentX;
} else {
mSpeedX = mousePercentX;
}
var mousePercentY:Number = this.mouseX/600;
var mSpeedY:Number;
if (dir == 1) {
mSpeedY = 1-mousePercentY;
} else {
mSpeedY = mousePercentY;
}
myBack.updateMe(mSpeedX,mSpeedY);
}
i have this code in main class and is called on every frame.
public class MyBg extends MovieClip {
public var destX:Number;
public var destY:Number;
public var inMotion:Boolean = false;
public function MyBg(){
}
public function updateMe(mSpeedX:Number,mSpeedY:Number):void{
//trace("Updating!");
var speed:Number = 1;
//trace("this.width: "+this.width+" stage.width: " + stage.width);
destX = Math.round(-((1100-800)*mSpeedX));
destY = Math.round(-((900-600)*mSpeedY));
if (this.x == destX) {
//trace("this.x: "+this.x+" destX.x: "+destX);
} else {
//trace("something");
this.x += Math.ceil((destX-this.x)*(speed/100));
inMotion=true;
}
if (this.y == destY) {
//trace("this.x: "+this.x+" destX.x: "+destX);
} else {
//trace("something");
this.y += Math.ceil((destY-this.y)*(speed/100));
inMotion=true;
}
}
}
and this is myBack’s class.
what happens when i run this code is that i can only scroll my image horizontally, but i want them to scroll independently. any ideas on why its doing this?