图像平移窗口调整大小问题

发布于 2024-11-08 07:44:10 字数 1733 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独自唱情﹋歌 2024-11-15 07:44:10

我认为,您看到的调整大小错误是因为您调用激活函数时没有为图像移动和设置边界。图像不断增加/减少它的 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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文