Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

panning help

Status
Not open for further replies.

abbott567

Technical User
Jun 18, 2007
38
GB
hey i am trying to pan an image in four directions but i can only get it to move left and right OR up and down...

not both =(

my code for left and right panning is

Code:
this.onMouseMove = function() {
constrainedMove(bg_mc, 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));
}
};
}
 
that IS my code lol

i tried adding destY and y instances...

i can get it to pan left and right

OR

up and down

OR

top left to bottom right but not all 4
 
You can just add Y axis in the code:
Code:
this.onMouseMove = function() {
	constrainedMove(bg_mc,4,1);
};
function constrainedMove(target:MovieClip, speed:Number, dir:Number) {
	var mousePercentX:Number = _xmouse/Stage.width;
	var mousePercentY:Number = _ymouse/Stage.height;
	var mSpeedX:Number;
	var mSpeedY:Number;
	if (dir == 0) {
		mSpeedX = 1-mousePercentX;
		mSpeedY = 1-mousePercentY;
	} else {
		mSpeedX = mousePercentX;
		mSpeedY = mousePercentY;
	}
	target.destX = Math.round(-((target._width-Stage.width)*mSpeedX));
	target.destY = Math.round(-((target._height-Stage.height)*mSpeedY));
	target.onEnterFrame = function() {
		if (target._x == target.destX && target._y == target.destY) {
			delete target.onEnterFrame;
		} else {
			target._x += Math.ceil((target.destX-target._x)*(speed/100));
			target._y += Math.ceil((target.destY-target._y)*(speed/100));
		}
	};
}

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top