拜托,任何人都可以指导我如何做这些事情。
我有一个面板和一个盒子,面板是我的组件面板(内部组件面板是例如.image,TextArea,Video)和 Box是我创建组件的目标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一样) 谢谢..
答案 0 :(得分:2)
退房Rogue-Development.com's Object Handles我已经用它来移动/调整组件大小非常成功。
答案 1 :(得分:0)
还可以试用比对象句柄更复杂的Pantaste library。
答案 2 :(得分:0)
转到http://sourceforge.net/projects/tcycomponents/
并根据需要下载软件包和演示。
使用TcyReziser组件轻松移动/调整大小,就像Delphi 2009一样!
此致 毛