I tried to do it while modifying your code as little as possible.
Copying is a lot more complex than moving and it can become a nightmare
if you have children embedded inside your Title Window. I think that you
may also have to clean up the BitmapData used as a drag proxy image to
avoid memory leaks. There are not only one way of doing this and it
might not be the best way but it's a start.
 
Good luck!
 
Whyves
 
 
---------------- BEGIN OF CODE -------------------
 
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute"
creationComplete="init();" >
 
 <mx:Panel x="47" y="78" width="200" height="200"
backgroundColor="#FFFFFF"
 layout="absolute"
 id="pan1" >
  <mx:TitleWindow id="myTitleWindow" title="My Title Window" x="10"
y="10" label="Button" mouseMove="mouseOverHandler(event);" width="160"
  backgroundColor="#F60B0B" height="77"/>
  <mx:Button x="40" y="118" label="Button2"/>
 
 </mx:Panel>
 <mx:Panel x="460" y="78" width="200" height="200"
backgroundColor="#FFFFFF"
 dragDrop="dragDropHandler(event)" id="pan2"
 dragEnter="dragEnterHandler(event)">
 </mx:Panel>
 

 <mx:Script>
 <![CDATA[
  import mx.core.BitmapAsset;
  import mx.core.FlexBitmap;
  import mx.core.IFlexDisplayObject;
 import mx.events.CloseEvent;
 import mx.containers.TitleWindow;
 import mx.managers.DragManager;
 import mx.core.DragSource;
 import mx.events.DragEvent;
 import mx.containers.Canvas;
 
 public function init():void
 {
  DragManager.showFeedback(DragManager.COPY);
 }
 
 private function mouseOverHandler(event:MouseEvent):void
 {
  // You need to make a copy of the window and pass it to the drag
source
  var dragData:TitleWindow = copyTitleWindow(myTitleWindow);
  var ds:DragSource= new DragSource();
  ds.addData(dragData, "can");
  
  // Drag Image
  var bd:BitmapData = new BitmapData(dragData.width, dragData.height);
  bd.draw(myTitleWindow);
  var dragImage:IFlexDisplayObject = new BitmapAsset(bd);
   
  DragManager.doDrag(myTitleWindow, ds, event, dragImage);
 }
 
 /**
  * Makes a copy of a Title Window 
  * 
  */
 protected function
copyTitleWindow(originalWindow:TitleWindow):TitleWindow {
  var newWindow:TitleWindow = new TitleWindow();
  with (newWindow) {
   title = originalWindow.title.concat(" copy");
   width = originalWindow.width;
   height = originalWindow.height;
   setStyle("backgroundColor",
originalWindow.getStyle("backgroundColor"));
  }
  return newWindow;
 }
 
 private function dragEnterHandler(event:DragEvent):void
 {
  if (event.dragSource.hasFormat("can"))
  {
   event.preventDefault();
   DragManager.showFeedback(DragManager.COPY);
   DragManager.acceptDragDrop(pan2);
  }
 }
 
 
 private function dragDropHandler(event:DragEvent):void
 {
  var window:TitleWindow= event.dragSource.dataForFormat("can") as
TitleWindow;
  window.x = 10;
  window.y = 10;
  window.showCloseButton=true;
  window.addEventListener(CloseEvent.CLOSE, fermer_h)
  pan2.addChild(window);
 }
 
 public function fermer_h(event:CloseEvent):void
 {
 pan2.removeChild(TitleWindow(event.currentTarget));
 }
 
 ]]>
 </mx:Script>
</mx:Application>

________________________________

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of soulflow132
Sent: Saturday, April 11, 2009 9:18 AM
To: flexcoders@yahoogroups.com
Subject: Re: re: [flexcoders] Problem drag and drop






I've tried what you said but its not working dude :confused::confused:
any suggestions please ?
-- 
View this message in context:
http://www.nabble.com/Problem-drag-and-drop-tp22997154p23001090.html
<http://www.nabble.com/Problem-drag-and-drop-tp22997154p23001090.html> 
Sent from the FlexCoders mailing list archive at Nabble.com.




Reply via email to