2017-07-29 95 views
0

我正在尝试使用多个按钮进行基于触摸的滚动MovieClip。我希望该按钮根据动画片段的mouseDownmouseUp事件进行移动。我希望有人能帮助我解决这个问题。在Adobe Flash上​​触摸滚动Android上的Air

var maxY:Number = 725; 
var minY:Number = 350; 
var _startY:Number; 
var _startMouseY:Number; 
addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); 

function mouseDownHandler(event:MouseEvent):void { 
    _startY = davies.y; 
    _startY = toa.y; 
    _startMouseY = mouseY; 
    stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMoveHandler, false, 0, true); 
    stage.addEventListener(MouseEvent.MOUSE_UP, stage_mouseUpHandler, false, 0, true); 
} 

function stage_mouseMoveHandler(event:MouseEvent):void { 
    var offsetY:Number = mouseY - _startMouseY; 
    background_scroll_product.y = Math.max(Math.min(maxY, _startY + offsetY), minY); 
    davies.y = Math.max(Math.min(maxY, _startY + offsetY), minY); 
    toa.y = Math.max(Math.min(maxY, _startY + offsetY), minY); 
} 

function stage_mouseUpHandler(event:MouseEvent):void { 
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMoveHandler); 
    stage.removeEventListener(MouseEvent.MOUSE_UP, stage_mouseUpHandler); 
} 

前后滚动后:

+0

什么是预期和实际的结果呢? –

+0

我想移动davies按钮,toa按钮和许多按钮滚动像movieclip,我共享的代码只滚动movieclip,如果我将该按钮分组到movieclip,我不能推动按钮在另一个框架上运行。对不起我的英文不好,我希望你能帮助我,谢谢你的回复 –

回答

0

解决方案

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 
+0

感谢您的帮助,但我已经尝试过,仍然有关于容器的问题,如: 1.我不能把图片放在上面作为框架的滚动和滚动在框架上移动。 2.当我滚动容器时,最后一个按钮nippon不会出现。 3.如果我按产品上的后退按钮,滚动容器不会丢失,仍然可以在Scane菜单中找到 您可以在以下链接中看到: [https://drive.google.com/open ?id = 0B366CR2EpFQNN29LU2MtRW1GRjQ] [https://drive.google.com/open?id=0B366CR2EpFQNNExSV2wwZnh1N2M] 我真的希望你的帮助来解决这个问题。 –

+0

Sory那个链接有问题,可以在这里找到; 1)。 2)。[https://www.dropbox.com/s/p9sthqrwor500k7/Product.fla?dl=0] 2)。 [https://www.dropbox.com/s/6b5ydkgaj20lk0a/Product.mp4?dl=0] –

+0

谢谢Atriace,我可以解决这个问题:)并再次感谢您的帮助 –