添加拖动;下拉到PopUp窗口中的TextArea

时间:2015-02-25 13:40:56

标签: actionscript-3 flex flash-builder4.5

我创建了一个ResizeableTitleWindow类,它扩展了Titlewindow(使其可以调整大小)。在RTW中我添加了一个TextArea并将RTW显示为PopUp。如何添加拖放到TextArea?

public function createPopUpEdit():void {
var rtw:ResizableTitleWindow = new ResizableTitleWindow();
var st:TextArea = new TextArea();
rtw.addElement(st);
PopUpManager.addPopUp(rtw, this, false);
PopUpManager.centerPopUp(rtw);

通常通过在.mxml文件中设置属性来执行此操作:

<s:TextArea id="st"
            dropEnabled="true"
            dragOver="onlyAllowCopyDragOverHandler(event)"
            dragDrop="myComponent_dragDropHandler(event)"
... 

但在这种情况下,st未在mxml中定义,而是使用&#34; new&#34;:

创建
var st:TextArea=new TextArea();

我想在createPopUpEdit函数中执行类似的操作:

st.dropEnabled="true";
st.dragOver="onlyAllowCopyDragOverHandler(event)";
etc.

1 个答案:

答案 0 :(得分:0)

编写以下代码。希望它会对你有所帮助。

            private var st:TextArea;
            private var rtw:TitleWindow;

            protected function init(event:FlexEvent):void
            {
                    rtw = new TitleWindow();
                    st = new TextArea();
                    st.width = 50;
                    st.height = 50;
                    st.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
                    st.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
                    rtw.width = 500;
                    rtw.height = 500;
                    rtw.addElement(st);
                    PopUpManager.addPopUp(rtw, this, false);
                    PopUpManager.centerPopUp(rtw);

            }

            private function onMouseDown(e:MouseEvent):void
            {
                st.startDrag(true,new Rectangle(0,0,rtw.width,rtw.height));
            }

            private function onMouseUp(e:MouseEvent):void
            {
                st.stopDrag();
            }

上面的代码将在popupView中拖放textarea。

修改

要添加事件动态,您可以这样做:

st.addEventListener(DragEvent.DRAG_OVER,onlyAllowCopyDragOverHandler);
st.addEventListener(DragEvent.DRAG_DROP,myComponent_dragDropHandler);