我在flash中有这个文档,我希望用鼠标移动来平移图像。当我测试电影时,它运行正常,任何问题。但是当我调整窗口大尺寸图像的位置时,它就会出错。我为此疯狂。有帮助吗?我将保留链接,以便您可以看到.fla文档。
http://www.megaupload.com/?d=TYS7BNJY
这是代码(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 = 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";
答案 0 :(得分:0)
我认为,您看到的调整大小错误是因为您在没有设置边界的情况下调用activate函数来移动图像。图像继续递增/递减它的x坐标。
您需要做的就是添加一个条件来检查图片是否超出帧(我想这是您所指的错误)&如果是,则将x坐标设置为最大/最小限制......如下所示:(到 activate()函数的末尾)
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;