2010-08-08 59 views
0

我想获取MC的百分比x坐标。例如,我的MC宽度为500px,高度为20px。当我点击我的MC的一部分时,我想获得我的MC'x坐标的百分比...(20%将是我的MC的100px ...)。任何人都知道如何去做?谢谢..AS3简单事件问题

我的代码

progressBa.addEventListener(MouseEvent.CLICK, barClick); 

    private function barClick(event:MouseEvent):void{ 
    perct=this.mouseX/progressBa.Width; //not sure how to do it.... 
    } 

回答

1

我不是很熟悉ActionScript,但是我用了trace(event)功能,看有什么事件中:

[MouseEvent type="click" bubbles=true cancelable=false eventPhase=2 localX=202 localY=5 stageX=296 stageY=88 relatedObject=null ctrlKey=false altKey=false shiftKey=false buttonDown=false delta=0] 

正如你所看到的, MouseEvent对象有一个名为localX的属性,这是您需要的属性。所以,对于影片剪辑的实际类是:

package 
{ 
    import flash.display.MovieClip; 
    import flash.events.*; 

    public class progressBa extends MovieClip 
    { 
    public function progressBa() 
    { 
     // Add a mouse event to this, the movieclip called progressBa 
     this.addEventListener(MouseEvent.CLICK, clickBar); 
    } 

    private function clickBar(e:MouseEvent):void 
    { 
     // Get click location's x-coordinate in percentages 
     var percent = 100 * e.localX/this.width; 
     trace(percent); 
    } 
    } 
} 

令我惊讶,我能够点击,因为抗混叠的,也许在100.018 ...%。

+0

不错......感谢您的帮助...... – FlyingCat 2010-08-08 17:40:16