2009-03-04 75 views
0

請任何人都可以指導我如何做到這一點。Flex:如何在運行時調整和移動組件?

我有一個面板和一個盒子,面板是我的組件面板(組件面板內部是圖像,文本區域,視頻)和 框是我的目標框爲我的組件創建。用戶可以選擇他/她想創建的組件(動態創建) 並將其拖動到目標Box(拖放事件)。然後在創建組件 後,用戶可以拖動他/她創建的組件並將其放置在目標文件夾的任何位置,並且用戶還可以調整他/她創建的組件(運行時調整大小)。

我有拖放此代碼,看來這個代碼僅適用於圖像

//-----action script-----// 
     private function dragIt(event:MouseEvent, value: String, objParent: String, objName: String):void 
     {   
      var dragInitiator:Image = event.currentTarget as Image;  
      var dragSource:DragSource = new DragSource(); 

      dragSource.addData(value,'value'); 
      dragSource.addData(objParent, 'parent'); 
      dragSource.addData(objName, 'objname'); 

      var dragProxy:Image = new Image(); 
      dragProxy.source = event.currentTarget.source; 


      DragManager.doDrag(dragInitiator, dragSource, event, dragProxy); 
     } 


     private function dragEnterHandler(event:DragEvent):void 
     { 
      var dropTarget:Box=event.currentTarget as Box; 
      dropTarget.setStyle("borderThickness", 5); 
      DragManager.acceptDragDrop(dropTarget); 
     } 

     private function dragExitHandler(event:DragEvent):void 
     { 
      var dropTarget:Box=event.currentTarget as Box;     
      revertBoxBorder();     
     }  

     private function revertBoxBorder():void 
     { 
      targetBox.setStyle("borderThickness", 1);     
     } 

     private function dragDropHandler(event:DragEvent):void 
     { 
      var value:String = event.dragSource.dataForFormat('value') as String; 
      var objParent:String = event.dragSource.dataForFormat('parent') as String; 
      if(value == "mp3") 
      { 
      //do something  
      } 
      else if (value == "image") 
      { 
       if (objParent == "panel") 
       { 
        var imgView: Image = new Image;     
        imgView.x = event.stageX; 
        imgView.y = event.stageY; 

        addChild(imgView); 
        imgView.name = String(getChildByName(imgView.name).parent.numChildren-1);  
        imgView.addEventListener(MouseEvent.MOUSE_MOVE, function(e:MouseEvent):void 
        { 
        dragIt(e, value, 'box', Image(e.target).name); 
       }); 
        imgView.source = ImgInsert; 
       } 
       else 
       { 
        var objName:String = event.dragSource.dataForFormat('objname') as String; 
        getChildByName(objName).parent.getChildAt(int(objName)).x = event.stageX; 
        getChildByName(objName).parent.getChildAt(int(objName)).y = event.stageY; 
       } 

      } 
      else if (value == "textarea") 
      { 
       //do something     
      } 

     } 

//-----mxml code------// 
<mx:Panel x="0" y="37" width="91" height="417" layout="absolute" title="Component" borderColor="#8DA5AB" color="#345860" borderStyle="outset"> 
    <mx:Image x="7" y="43" width="21" height="18" source="{TxtAreaInsert}" mouseMove="dragIt(event,'textarea','panel','')"/> 
    <mx:Image x="36" y="43" width="21" height="18" source="{ImgInsert}" mouseMove="dragIt(event,'image','panel','')"/> 
    <mx:Image x="36" y="80" width="21" height="18" source="{Mp3Insert}" mouseMove="dragIt(event,'mp3','panel','')"/> 
    <mx:Image x="7" y="80" width="21" height="18" source="{VdoInsert}" mouseMove="dragIt(event,'video','panel','')"/> 
</mx:Panel> 
<mx:Box id="targetBox" y="37" width="589" height="417" borderColor="#8CC2E8" backgroundColor="#D5DBEE" 
    dragExit="dragExitHandler(event)" dragEnter="dragEnterHandler(event)" dragDrop="dragDropHandler(event)" left="99"> 
</mx:Box>; 

如何將這樣的非圖像部分像TxtArea?如何調整目標框中的組件大小? (這就像創建組件時的flex一樣的GUI) 謝謝..

回答

0

轉到http://sourceforge.net/projects/tcycomponents/
並下載包和演示,如果你想。

使用TcyReziser組件輕鬆移動/調整大小像德爾福2009年!

問候, 毛

+0

鏈接的部件是爲Delphi,不針對Flex。 – 2013-01-24 15:48:49

相關問題