2013-12-21 100 views
0

製作一個簡單的應用程序,其中包含一個可更改文本框值的滑塊,但每當我放下滑塊時,它都會回到其0位置。我需要它留在原地。請幫忙!AS3拖動總是回到原來的位置?

代碼:

 theroot.settings_but.phone1.slider.addEventListener(MouseEvent.MOUSE_DOWN, slide); 


     public function slide(e:MouseEvent):void 
    { 


      stage.addEventListener(MouseEvent.MOUSE_UP, dragstop); 
      var bounds:Rectangle = new Rectangle(0,27,550,0); 
      theroot.settings_but.phone1.slider.startDrag(false, bounds); 
      txtboxint = setInterval(changetextbox, 500); 

    } 
    public function dragstop(e:MouseEvent):void 
    { 
     stage.removeEventListener(MouseEvent.MOUSE_UP, dragstop); 
     clearInterval(txtboxint); 
     trace("what", e.target.x, e.currentTarget, e.target.name) // returns proper x value, [object Stage], slider 
     trace("almost", theroot.settings_but.phone1.slider.x);// returns proper x value 
     theroot.settings_but.phone1.slider.stopDrag(); 
     trace("last", theroot.settings_but.phone1.slider.x); //returns proper x value 
    } 
    public function changetextbox():void 
    { 
     trace(theroot.settings_but.phone1.slider.x) //returns proper x value 
     theroot.settings_but.phone1txt.text = (Math.floor(((theroot.settings_but.phone1.slider.x)/550) * 40)); 
    } 
+0

我認爲它必須在代碼中的其他地方出現問題。這看起來很好。 – imcg

回答

0

嘗試此,

 theroot.settings_but.phone1.slider.addEventListener(MouseEvent.MOUSE_DOWN, slide); 


    public function slide(e:MouseEvent):void 
    { 
     theroot.settings_but.phone1.slider.removeEventListener(MouseEvent.MOUSE_DOWN, slide); 
     stage.addEventListener(MouseEvent.MOUSE_UP, dragstop); 
     var bounds:Rectangle = new Rectangle(0,27,550,0); 
     theroot.settings_but.phone1.slider.startDrag(false, bounds); 
theroot.settings_but.phone1.slider.addEventListener(Event.ENTER_FRAME,changetextbox);  
    } 

    public function dragstop(e:MouseEvent):void 
    { 
     theroot.settings_but.phone1.slider.stopDrag(); 
     stage.removeEventListener(MouseEvent.MOUSE_UP, dragstop); 
     trace("what", e.target.x, e.currentTarget, e.target.name) // returns proper x value, [object Stage], slider 
     trace("almost", theroot.settings_but.phone1.slider.x);// returns proper x value   
     trace("last", theroot.settings_but.phone1.slider.x); //returns proper x value     theroot.settings_but.phone1.slider.removeEventListener(Event.ENTER_FRAME,changetextbox); 
     theroot.settings_but.phone1.slider.addEventListener(MouseEvent.MOUSE_DOWN, slide); 
    } 

    public function changetextbox(e:Event):void 
    { 
     trace(theroot.settings_but.phone1.slider.x) //returns proper x value 
     theroot.settings_but.phone1txt.text = (Math.floor(((theroot.settings_but.phone1.slider.x)/550) * 40)); 
    } 
+0

不幸的是沒有去。 – AlexVision

+0

檢查我的編輯代碼.. –

+0

對不起,但再次,沒有去,如果我釋放鼠標的任何地方,但滑塊mc,它保持原地,直到我點擊屏幕上的任何其他地方。然後它迅速恢復。非常沮喪.. – AlexVision

0

問題是事件冒泡到主MC,這引起了MC與滑塊內轉到幀0

感謝所有的幫助!

相關問題