组件脱离了另一个组件

时间:2010-08-31 18:22:23

标签: flex actionscript-3 flex4

如果我从组件中拖动textInput并将其放在另一个组件的末尾附近,则textInput将超出dropZone。

有任何想法如何解决这个问题?

谢谢

编辑:

<?xml version="1.0" encoding="utf-8"?>
<s:Group 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="500" xmlns:components="components.*" >

        protected function textInput_mouseDownHandler(event:MouseEvent):void
      {

      var dragI:Label=event.currentTarget as Label;
      var ds:DragSource=new DragSource();
      ds.addData(dragI,"TextInput");
      DragManager.doDrag(dragI,ds,event);
      }
 <s:BorderContainer width="100%" height="100%">
    <s:layout>
      <s:VerticalLayout gap="10"/>
    </s:layout>  
<s:Label text="TextInput"   mouseMove="textInput_mouseDownHandler(event )" dragComplete="dragCompleteHandler(event)" />

 </s:BorderContainer>

和dropZone组件:

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" height="500" width="700" xmlns:components="components.*" >
  <fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
  </fx:Declarations>

 protected function dragDropHandler(event:DragEvent):void
      {

        if (event.dragSource.hasFormat("TextInput")){

          var draggedText:TextInput=new TextInput();
          draggedText.x = event.currentTarget.mouseX;
          draggedText.y = event.currentTarget.mouseY;
          event.currentTarget.addElement(draggedText);
}
}
   protected function dragEnterHandler(event:DragEvent):void
      {
        if(event.dragSource.hasFormat("TextInput")  )
        {
          var dropTarget:BorderContainer= event.currentTarget as BorderContainer;
          DragManager.acceptDragDrop(dropTarget);   
}
}

 <s:BorderContainer width="100%" height="100%" dragDrop="dragDropHandler(event)"
                     dragEnter="dragEnterHandler(event)"/>
</s:Group>

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

在布局对象上,将clipAndEnableScrolling设置为true。这将导致布局剪切所有内容,这些内容位于容器的边界之外。如果需要滚动,则仍需要将组包装在滚动条中。

<s:BorderContainer width="100%" height="100%"> 
    <s:layout> 
      <s:VerticalLayout gap="10" clipAndEnableScrolling="true"/> 
    </s:layout>   
<s:Label text="TextInput"   mouseMove="textInput_mouseDownHandler(event )" dragComplete="dragCompleteHandler(event)" /> 

 </s:BorderContainer> 

clipAndEnableScrolling是所有布局的属性,VerticalLayout,Horizo​​ntalLayout和BasicLayout,仅举几例。