1 Reply Latest reply on Aug 31, 2007 3:25 AM by MikeBurns76

    Custom logic in Drag and Drog List HELP!

    richiemotoki
      Hi guys,

      I'm currently writing an application with two lists with the following conditions:

      1. Items from List1 is copied to List2 when using mouse drag.
      2. Item name from List1 that already exists in List2, ignore the drag command.
      3. Drag items within the List2 will move the order of the items listed in List2.

      I have done the first two conditions but i can't seem to do the third conditon... can anyone please help??

      Many many thanks!

      My sample codes are as follows:


      private function onDragDrop(event:DragEvent):void
      {

      if (event.dragSource.hasFormat("items"))
      {
      event.preventDefault();
      event.currentTarget.hideDropFeedback(event);
      var dropTarget:List = List(event.currentTarget);
      var itemsArray:Array = event.dragSource.dataForFormat("items") as Array;

      if (inAlbumList != null)
      {
      for(var i:Number = 0; i < inAlbumList.length; i++)
      {
      if (itemsArray[0].label == inAlbumList .label)
      {
      //Alert.show("same");
      return;
      }
      }
      }
      var dropLoc:int = dropTarget.calculateDropIndex(event);
      var tempItem:Object = {name: itemsArray[0].name,
      pos: dropLoc,
      label: itemsArray[0].label,
      data: itemsArray[0]};
      if (inAlbumList != null)
      inAlbumList.addItemAt(tempItem, dropLoc);
      else
      {
      inAlbumList = new ArrayCollection();
      inAlbumList.addItemAt(tempItem, dropLoc);
      }
      }
      }

      <mx:List x="10" y="86" height="206" id="listSongs" width="245" dataProvider="{songList}"
      dragEnabled="true" dropEnabled="false" dragMoveEnabled="true"
      dragComplete="onDragComplete(event)"></mx:List>

      <mx:List x="280" y="86" height="206" width="254" id="listAlbum"
      dataProvider="{inAlbumList}" dragEnabled="true" dropEnabled="true" dragMoveEnabled="true"
      dragDrop="onDragDrop(event)"></mx:List>