图像平移窗口调整大小问题
我在 Flash 中有这个文档,我希望图像可以通过鼠标移动进行平移。当我测试电影时,它运行正常,没有任何问题。但是当我调整窗口大小以调整大图像的位置时,一切都出错了。
这是代码(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";
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 = 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";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,您看到的调整大小错误是因为您调用激活函数时没有为图像移动和设置边界。图像不断增加/减少它的 x 坐标。
您需要做的就是添加一个条件来检查图片是否超出框架(我想这就是您所指的错误)&如果是,则将 x 坐标设置为最大/最小限制...类似这样:(到 activate() 函数的末尾)
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)