4 Replies Latest reply on Jan 8, 2010 2:48 PM by Jason Szeto

    Drag and Drop Help


      Hey guys,


      I have icons that I want to drag and drop onto a canvas. I have the drag and drop thing down, but I want to make it so that one icon can not be dragged in to the same place twice.


      For example, if you have a Generator Icon.

      What I did was make a specific canvas for each spot I want them to go, when you click on the icon the canvas border goes red, telling you where to put it, when you drop it, the canvas border color goes white again.


      Ok no problem. But if you want to bring out multiple generators. I made spots for 10 generators. Each with their own canvas. I just can't figure out how to tell Flex that the first canvas already got a generator so make then next canvas border red and drop it there.


      Confused? Yea me too. Here is the code.


      private function genDoDragEnter(event:DragEvent):void
                  DragManager.acceptDragDrop(UIComponent (event.target));
                  private function genDoDragDrop(event:DragEvent):void
                      var img:Image;
                      if (event.dragInitiator.parent == genIconCanvas1)
                          img = event.dragInitiator as Image;
                          genIconCanvas1.setStyle("borderColor", "#ffffff");
                          img = new Image();
                          img.source = (event.dragInitiator as Image).source;
                          img.addEventListener(MouseEvent.MOUSE_DOWN, doDragStart);
                          genIconCanvas1.setStyle("borderColor", "#ffffff");
                      img.x = event.localX -
                      (event.dragSource.dataForFormat("localX") as Number);
                      img.y = event.localY -
                      (event.dragSource.dataForFormat("localY") as Number);
                  private function doDragStart(event:MouseEvent):void
                  var dragInitiator:Image = event.currentTarget as Image;
                  var dragSource:DragSource = new DragSource();
                  var dragProxy:Image = new Image();
                  genIconCanvas1.setStyle("borderColor", "#ff0000");
                  dragProxy.source = dragInitiator.source;
                  dragProxy.width = dragInitiator.width;
                  dragProxy.height = dragInitiator.height;
                  dragProxy.buttonMode = true;
                  dragSource.addData(event.localX, "localX");
                  dragSource.addData(event.localY, "localY");
                  DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);