Flex:如何在运行时调整组件大小和移动组件?

发布于 2024-07-14 15:41:55 字数 4054 浏览 7 评论 0原文

请任何人都可以指导我如何做这些事情。

我有一个面板和一个盒子,面板是我的组件面板(内部组件面板是例如图像、文本区域、视频)和 Box 是我创建组件的目标 Box。 用户可以选择他/她想要创建的组件(动态创建) 并将其拖动到目标框(拖放事件)。 然后创建组件后 用户可以拖动他/她创建的组件并将其放置在目标上的任何位置 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) 谢谢..

Please, anyone can guide me how to do this stuff.

I have a pannel and a box, The pannel is my component pannel(inside component pannel is eg. image, TextArea, Video) and
Box is my target Box for my component creation. The user can select a component he/she want to create (dynamic creation)
and drag it to target Box(drag and drop event). Then after creating the component
the user can drag the component that he/she created and place anywhere on target
Box and also the user can resize the component that he/she created(runtime resize).

i have this code for drag and drop and it seems this code works only on image

//-----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>;

How to move thus non image component like TxtArea? How to resize the component inside target box?
(This is like GUI of flex when creating component)
Thank you..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

赏烟花じ飞满天 2024-07-21 15:41:55

查看 Rogue-Development.com 的对象句柄 我已经使用它取得了相当好的成功用于移动/调整组件大小。

check out Rogue-Development.com's Object Handles I've used this with pretty good success for moving / resizing components.

蓝眼睛不忧郁 2024-07-21 15:41:55

还可以尝试 Pantaste 库,它比对象句柄复杂得多。

Also try out the Pantaste library which is a lot more sophisticated than Object Handles.

茶色山野 2024-07-21 15:41:55

转到 http://sourceforge.net/projects/tcycomponents/
如果需要的话,可以下载包和演示。

使用 TcyReziser 组件可以像 Delphi 2009 一样轻松移动/调整大小!

问候,
毛里西奥

Goto http://sourceforge.net/projects/tcycomponents/
and download package and demo if you want.

Use TcyReziser component for easy moving/resizing like Delphi 2009 does!

Regards,
Mauricio

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文