解决方案
1:尝试用以下替换Math.max(Math.min(maxY, _startY + offsetY), minY);:
clamp(mouseY - _startY + offsetY, minY, maxY);
function clamp(original:Number, low:Number, high:Number):Number {
return (original > high) ? high : (original < low) ? low : original;
}
2:将所有内容移动到一个容器中。移动一个对象比移动多个对象更容易。
多个对象:
0:MainTimeline
0:background_scroll_product //.y += offsetY;
1:davies //.y += offsetY;
2:toa //.y += offsetY;
...
一个对象:
0:MainTimeline
0:container //.y += offsetY;
0:background_scroll_product
1:davies
2:toa
...
示范
下面的代码,你可以拖放到一个新的项目,它将与编译工作滚动容器。请注意,其他人在问问题时可能需要这样的Minimal, Complete, and Verifiable example。
var background_scroll_product, davies, toa;
demoSetup();
/* ^^^ Omit this if you already have these objects defined ^^^ */
// Create a container for our content.
var container:Sprite = new Sprite();
addChild(container);
// Put the content inside the container.
container.addChild(background_scroll_product);
container.addChild(davies);
container.addChild(toa);
// setup the min based on the size of the contents.
var loc:Object = {
"max":50,
"min":stage.stageHeight - container.height
};
addEventListener("mouseDown", mouseHandler);
function mouseHandler(e:Event):void {
switch (e.type) {
case "mouseDown":
loc.start = mouseY;
loc.container = container.y;
addEventListener("mouseUp", mouseHandler);
addEventListener("mouseMove", mouseHandler);
break;
case "mouseUp":
removeEventListener("mouseUp", mouseHandler)
removeEventListener("mouseMove", mouseHandler);
break;
case "mouseMove":
// Scroll the container.
container.y = clamp(mouseY - loc.start + loc.container, loc.min, loc.max);
break;
}
}
function clamp(original:Number, low:Number, high:Number):Number {
return (original > high) ? high : (original < low) ? low : original;
}
function demoSetup():void {
// This sets up a facsimile of the project, to create a Minimal, and Verifiable example.
var bg:Sprite = new Sprite();
bg.graphics.beginFill(0xA1A1A1);
bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
bg.graphics.endFill();
addChild(bg);
background_scroll_product = new Shape();
background_scroll_product.graphics.beginFill(0xf0e3e5);
background_scroll_product.graphics.drawRect(0, 0, 250, 750);
background_scroll_product.graphics.endFill();
davies = new Shape();
davies.graphics.beginFill(0x243066);
davies.graphics.drawRect(0, 0, 200, 400);
davies.graphics.endFill();
davies.x = davies.y = 25;
toa = new Shape();
toa.graphics.beginFill(0xdc3734);
toa.graphics.drawRect(0, 0, 200, 200);
toa.graphics.endFill();
toa.x = 25;
toa.y = 525;
}
响应FLA
我强烈建议你不要用工作场景,特别是因为他们创造肮脏的国家不是迫切辨认。事实上,由于您似乎正在努力实现移动应用,您绝对应该考虑使用完整的UI框架,如FeathersUI。不管...
挥之不去的集装箱
的Timeline试图把每一帧作为程序的唯一状态。您可以通过这种方式直观地构建用户界面,但它很笨拙。此外,正如您发现的那样,当您将WYSIWYG与功能性编程混合在一起时,Flash UI永远不会意识到并永远不会“清理”。您手动添加了addChild(container),因此您还需要手动添加removeChild(container)。你可以把它放在你的监听器函数里面,作为后退按钮。
集装箱悬停在标题栏
考虑你的主菜单heiarchy:
0: instance15 (Shape)
1: button_back (SimpleButton)
2: instance16 (StaticText)
3: container (Sprite)
正如你所看到的,层0通过2是你的顶部菜单的对象。在菜单后面移动container与调用addChildAt()一样简单,并将第二个参数设置为0索引。
addChildAt(container, 0);
最后图像被剪辑
这样做的原因是,你的内容不位于y:0。如果要解决这个问题,无论是在y:0移动到开始的内容,或加上抵消你的第一个图形的最小值的...
"min":this.loaderInfo.height - container.height - davies.y