I have this document in flash where I want an image to pan with mouse movement. When I test the movie it runs OK with any problem. But when I resize the window the position of the big image, it goes all wrong.
Here is the code (Actionscript 2.0):
var boundX:Number = bigPic._x+activator._x*(bigPic._width/activator._width);
var diffX:Number = bigPic._width-activator._width;
var easeSpeed:Number = 7;
function resizeHandler():Void {
g1_mc._x = 0;
g1_mc._y = 0;
g1_mc._height = Stage.height;
g1_mc._width = (Stage.width-activator._width)/2;
g2_mc._y = 0;
g2_mc._height = Stage.height;
g2_mc._width = (Stage.width-activator._width)/2;
g2_mc._x = Stage.width-g2_mc._width;
activator._x = g1_mc._width;
//trace('bigPic' + bigPic._x);
//trace('activatorx' + activator._x);
boundX = bigPic._x+activator._x*(bigPic._width/activator._width);
diffX = bigPic._width-activator._width;
var divX:Number = _xmouse / activator._width;
var moveX:Number = divX*diffX;
}
function activate():Void {
var divX:Number = _xmouse / activator._width;
var moveX:Number = divX*diffX;
trace(bigPic._x);
bigPic._x += (boundX-moveX-bigPic._x) / easeSpeed;
//trace('DIVX' + divX);
/*trace('boundX' + boundX);
trace('moveX' + moveX);*/
}
activator.onRollOver = function():Void {
addEnterFrameEvent();
};
activator.onRollOut 开发者_JAVA百科= function():Void {
removeEnterFrameEvent();
};
function addEnterFrameEvent():Void {
this.onEnterFrame = activate;
}
function removeEnterFrameEvent():Void {
delete this.onEnterFrame;
}
var stageListener:Object = new Object();
stageListener.onResize = function():Void {
resizeHandler();
delete _root.onEnterFrame;
};
Stage.addListener(stageListener);
stageListener.onResize();
Stage.scaleMode = "noScale";
Stage.align = "TL";
I think, the resize error you see is because you call the activate function without a set boundary for the image to move & the image keeps on incrementing/decrementing it's x coordinates.
All you need to do is add a condition to check if the picture is going out of frame (I suppose that is the error you are referring to) & if it is, then set the x coordinates to the maximum / minimum limits...Something like this : (to the end of your activate() function)
var MinimumX:Number = Stage.width - bigPic._width;
var MaximumX:Number = 0;
if(bigPic._x < MinimumX) bigPic._x = MinimumX;
if(bigPic._x > MaximumX) bigPic._x = MaximumX;
精彩评论