3 Replies Latest reply on Jun 21, 2010 10:09 AM by prodigy1485

    Copying a componenet that is manually "drag and dropped"

    Tikis_Mikis
      Hi there I am using this code as the basis of my project: http://blogs.adobe.com/flexdoc/2007/03/creating_resizable_and_draggab.html

      I modified the code and came up with my own drag/drop functions:

      private function tbMouseMoveHandler(event:MouseEvent):void
      {
      // create the filterEditObj in order to display its data in the Filter Settings Edit form
      // - form id =
      // == nodeEditObj = Object(Panel(event.currentTarget));
      nodeEditObj = Object(Button(event.currentTarget)).data;

      //Alert.show("test");
      // here call to DB to get the id's information


      // == var dragInitiator:Panel=Panel(event.currentTarget);
      var dragInitiator:Button = Button(event.currentTarget);
      var ds:DragSource = new DragSource();
      ds.addData(event.currentTarget, 'panel');

      // Update the xOff and yOff variables to show the
      // current mouse location in the Panel.
      xOff = event.currentTarget.mouseX;
      yOff = event.currentTarget.mouseY;

      // Initiate d&d.
      DragManager.doDrag(dragInitiator, ds, event);
      }

      // Function called by the canvas dragEnter event; enables dropping
      private function doDragEnter(event:DragEvent):void
      {
      DragManager.acceptDragDrop(Canvas(event.target));
      }

      // Function called by the Canvas dragDrop event;
      // Sets the panel's position,
      // "dropping" it in its new location.
      private function doDragDropMemberCanvas(event:DragEvent):void
      {
      // Compensate for the mouse pointer's location in the title bar.
      var tempX:int = event.currentTarget.mouseX - xOff;
      event.dragInitiator.x = tempX;

      var tempY:int = event.currentTarget.mouseY - yOff;
      event.dragInitiator.y = tempY;


      //var filterSetObj:String = List(event.dragInitiator).toString();

      //Alert.show(filterSetObj);

      //var testB:Button = new Button();


      // drop a child if it is dragged into the canvas
      //=========memberFilters.addChild(Panel(event.dragInitiator));
      memberFilters.addChild(Button(event.dragInitiator));
      // Put the dragged panel on top of all other components.
      // == memberFilters.setChildIndex(Panel(event.dragInitiator), memberFilters.numChildren-1);
      memberFilters.setChildIndex(Button(event.dragInitiator), memberFilters.numChildren-1);

      // function call to update the filter set
      //updateFilterSet();
      }

      As you can see I'm not using panels but Button componenets that have the "data" attributes set to an object containing data related to it.

      Anyway what I am trying to do is instead of dropping the button that i have clicked and dragged to instead create an instance (a copy) of a button that has been clicked AND dragged at the same time so that if there is only one button after I click and drag there will be two buttons with identical data except that their "id" will be different - i will probably use some way to make sure that no two ids are the same.

      Any ideas, tips? thank you so much!