2013-04-15 80 views

回答

1

這裏是my example

//應用

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" 
      minWidth="955" minHeight="600" creationComplete="init(event)"> 
<fx:Script> 
    <![CDATA[ 
     import com.dragpanel.MyPanel; 

     import mx.events.FlexEvent; 

     protected function init(event:FlexEvent):void 
     { 
      var panel:MyPanel = new MyPanel(); 
      panel.width = 300; 
      panel.height = 200; 
      panel.title = "Hello"; 

      this.addElement(panel); 
     } 

    ]]> 
</fx:Script> 

</s:Application> 

//MyPanel.mxml

<?xml version="1.0" encoding="utf-8"?> 
<s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    width="150" height="80" title="Hello" 
    mouseDown="onMouseDown(event)" mouseUp="onMouseUp(event)" 
    skinClass="com.dragpanel.PanelNoTitleBar"> 

<fx:Script> 
    <![CDATA[ 
     protected function onMouseDown(event:MouseEvent):void 
     { 
      this.startDrag(); 
     } 

     protected function onMouseUp(event:MouseEvent):void 
     { 
      this.stopDrag(); 
     } 

    ]]> 
</fx:Script> 

<s:HGroup verticalAlign="bottom" x="10" y="10"> 
    <s:Label text="Name:"/> 
    <s:TextInput width="60"/> 
</s:HGroup> 
</s:Panel> 
+0

感謝您的代碼,但它拖動ñ滴,我想只是移動我的面板,如在這個例子中:http://blog.ninjacaptain.com/2008/06/draggable-panel-with-close-button/但我的面板沒有標題欄 –

+0

好吧,我的錯,我會盡量找到另一種解決方案。對不起 – Anton

+1

我改變了我的代碼。現在它只能拖動。不可丟棄:) – Anton

0

你如何使用標題欄開始拖動?你在面板的標題欄部分有一個mouseDown監聽器嗎?您可以將mouseDown偵聽器移動到面板本身。

+0

請你能解釋我如何鼠標按下監聽器移動到面板本身? –

+0

看起來你已經得到了你的答案。在Anton的例子中,很明顯:'' – NTyler

+0

是的,現在我明白你的意思了=)謝謝! –

相關問題