Flash 如何使用此代码整合GlobalTopolocal?

Flash 如何使用此代码整合GlobalTopolocal?,flash,actionscript-3,Flash,Actionscript 3,我有这组代码来创建一个简单的前后图像展示器: import com.greensock.*; import com.greensock.easing.*; function init() : void { sliderbar_mc.buttonMode = true; sliderbar_mc.addEventListener(MouseEvent.MOUSE_DOWN,moveSliderbar); stage.addEventListener(MouseEvent

我有这组代码来创建一个简单的前后图像展示器:

import com.greensock.*;
import com.greensock.easing.*;

function init() : void  {
    sliderbar_mc.buttonMode = true;
    sliderbar_mc.addEventListener(MouseEvent.MOUSE_DOWN,moveSliderbar);
    stage.addEventListener(MouseEvent.MOUSE_UP,stopSliderbar);
    mask_mc.alpha = 0;
    after_mc.mask = mask_mc;
    TweenLite.to(sliderbar_mc,4,{x:stage.stageWidth/2,ease:Elastic.easeOut});
    TweenLite.to(mask_mc,4,{x:stage.stageWidth/2,ease:Elastic.easeOut});
}  

function moveSliderbar(event:MouseEvent):void {
    stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
}  

function stopSliderbar(event:MouseEvent):void{
    stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
}

function mouseMoveHandler(event:MouseEvent):void{
    sliderbar_mc.x = mouseX;
    if (sliderbar_mc.x > stage.stageWidth){
        sliderbar_mc.x = stage.stageWidth;
    }
    else if(sliderbar_mc.x < 0){
        sliderbar_mc.x = 0;
    }
    mask_mc.x = sliderbar_mc.x;
}

init();
import com.greensock.*;
导入com.greensock.com;
函数init():void{
sliderbar_mc.buttonMode=真;
sliderbar\u mc.addEventListener(MouseeEvent.MOUSE\u DOWN,moveSliderbar);
stage.addEventListener(MouseEvent.MOUSE\u UP,stopSliderbar);
掩模μmc.alpha=0;
在_mc.mask之后=mask _mc;
TweenLite.to(sliderbar_mc,4,{x:stage.stageWidth/2,ease:Elastic.easeOut});
TweenLite.to(mask_mc,4,{x:stage.stageWidth/2,ease:Elastic.easeOut});
}  
函数moveSliderbar(事件:MouseEvent):void{
stage.addEventListener(MouseEvent.MOUSE\u MOVE,mouseMoveHandler);
}  
函数stopSliderbar(事件:MouseeEvent):无效{
stage.removeEventListener(MouseEvent.MOUSE\u MOVE,mouseMoveHandler);
}
函数mouseMoveHandler(事件:MouseEvent):void{
sliderbar_mc.x=鼠标;
如果(滑块Bar_mc.x>舞台宽度){
滑块Bar_mc.x=stage.stageWidth;
}
else if(滑块b_mc.x<0){
滑块杆_mc.x=0;
}
掩模x=滑块x;
}
init();
但现在我需要把展示区放在舞台上某个地方的电影剪辑中,就我的一生而言,我不知道如何使用GlobalTopolocal来完成这项工作。。。以下是我的尝试:

import com.greensock.*;
import com.greensock.easing.*;

function init():void  {
    area_mc.sliderbar_mc.buttonMode = true;
    area_mc.sliderbar_mc.addEventListener(MouseEvent.MOUSE_DOWN,moveSliderbar);
    stage.addEventListener(MouseEvent.MOUSE_UP,stopSliderbar);
    area_mc.mask_mc.alpha = 0;
    area_mc.after_mc.mask = area_mc.mask_mc;
    TweenLite.to(area_mc.sliderbar_mc,3,{x:stage.stageWidth/2,ease:Elastic.easeOut});
    TweenLite.to(area_mc.mask_mc,3,{x:stage.stageWidth/2,ease:Elastic.easeOut});
}  

function moveSliderbar(event:MouseEvent):void {
    stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
}  

function stopSliderbar(event:MouseEvent):void {
    stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
}

function mouseMoveHandler(event:MouseEvent):void {
    var topLeft:Point = area_mc.localToGlobal(new Point(0, 0));
    var bottomRight:Point = area_mc.localToGlobal(new Point(width, height));
    area_mc.sliderbar_mc.x = area_mc.mouseX;
    if (area_mc.mouseX > topLeft.x) {
        area_mc.sliderbar_mc.x = topLeft.x;
    }
    else if(area_mc.mouseX < bottomRight.x){
        area_mc.sliderbar_mc.x = bottomRight.x;
    }
    area_mc.mask_mc.x = area_mc.sliderbar_mc.x;
}

init();
import com.greensock.*;
导入com.greensock.com;
函数init():void{
area_mc.sliderbar_mc.buttonMode=true;
区域\u mc.sliderbar\u mc.addEventListener(MouseEvent.MOUSE\u DOWN,moveSliderbar);
stage.addEventListener(MouseEvent.MOUSE\u UP,stopSliderbar);
面积μmc.maskμmc.alpha=0;
遮罩后的面积=遮罩面积;
TweenLite.to(区域_mc.滑块_mc,3,{x:stage.stageWidth/2,ease:Elastic.easeOut});
TweenLite.to(面积_mc.mask _mc,3,{x:stage.stageWidth/2,ease:Elastic.easeOut});
}  
函数moveSliderbar(事件:MouseEvent):void{
stage.addEventListener(MouseEvent.MOUSE\u MOVE,mouseMoveHandler);
}  
函数stopSliderbar(事件:MouseeEvent):无效{
stage.removeEventListener(MouseEvent.MOUSE\u MOVE,mouseMoveHandler);
}
函数mouseMoveHandler(事件:MouseEvent):void{
var topLeft:Point=area_mc.localToGlobal(新点(0,0));
var bottomRight:Point=面积_mc.localToGlobal(新点(宽度、高度));
area_mc.sliderbar_mc.x=area_mc.mouseX;
如果(面积_mc.mouseX>topLeft.x){
面积滑块=左上角x;
}
else if(面积μm.mouseX

显然,它工作不正常,我知道这都是在mouseMoveHandler函数中,有人能给我一些提示吗?

好的,我玩了一会儿,我想我能让它做你想做的事情。它仍然有相当多的纠结要解决,代码是丑陋的,但我已经尝试保持你试图使用的方法。为此,我在舞台上制作了所有必要的剪辑。我假设area_mc是您试图在其中工作的剪辑,其他所有内容都在其中

明天我可能会多做一点,但它在这里;告诉我它是否在做你需要的事情:

var maxlenX:int = area_mc.x+area_mc.width;//calculate the maximum x area of our clip. I     do this outside the function
// Because the width will change as you move the slider. There are more elegant ways to do this, but I think this is sufficient
// for now. This will be used to stop the slider when it moves all the way to the right of our clip.
function mouseMoveHandler(event:MouseEvent):void {
    var topLeft:Point = area_mc.localToGlobal(new Point(0,0));//Translate the top   left of the clip into global coords.
    var bottomRight:Point = new Point(maxlenX,area_mc.y);//Use the maxlenX variable created above to get the bottom right point. (no need for a point here TBH).
    area_mc.sliderbar_mc.x = area_mc.mouseX;
    if (mouseX <= topLeft.x){//If the mouse is to the left of the top left point...
        area_mc.sliderbar_mc.x = area_mc.globalToLocal(new Point(topLeft.x,topLeft.y)).x;//keep the slider from moving left.
    } else if (mouseX >= bottomRight.x){//if the mouse is to the right of the bottom right point...
        area_mc.sliderbar_mc.x = area_mc.globalToLocal(new Point(bottomRight.x,bottomRight.y)).x;//keep the slider form moving right.
    }
    area_mc.mask_mc.x = area_mc.sliderbar_mc.x;//move the mask.
}
var maxlenX:int=area_mc.x+area_mc.width//计算剪辑的最大x面积。我在功能之外做这个
//因为宽度会随着滑块的移动而改变。有更优雅的方法可以做到这一点,但我认为这已经足够了
//现在。这将用于在滑块一直移动到剪辑右侧时停止滑块。
函数mouseMoveHandler(事件:MouseEvent):void{
var topLeft:Point=area_mc.localToGlobal(新点(0,0));//将剪辑的左上角转换为全局坐标。
var bottomRight:Point=new Point(maxlenX,area_mc.y);//使用上面创建的maxlenX变量获取右下角点。(此处不需要点TBH)。
area_mc.sliderbar_mc.x=area_mc.mouseX;
如果(mouseX=bottomRight.x){//如果鼠标位于右下角点的右侧。。。
area_mc.sliderbar_mc.x=area_mc.globalToLocal(新点(bottomRight.x,bottomRight.y)).x;//保持滑块窗体向右移动。
}
area\u mc.mask\u mc.x=area\u mc.sliderbar\u mc.x;//移动遮罩。
}

mouseMoveHandler中的代码令人困惑。你能解释一下你想做什么吗?谢谢你的回复,它很有魅力!localToGlobal是我所知道的处理这种情况的唯一方法,您有什么建议吗?我试过了,但它没有限制:函数mousemoveholder(事件:MouseEvent):void{area_mc.sliderbar_mc.x=area_mc.mouseX;var left:Number=area_mc.x-(area_mc.width/2);var right:Number=area_mc.x+(area_mc.sliderbar_mc.x>right){area_mc.sliderbar_mc.x=right;}如果(area_mc.sliderbar_mc.x