Drag drop objects to multiple target areas

Hi,
I am trying to  make a quiz on metals. I have several elements which i want to fall into  multiple target areas (e.g. the target areas are shaded grey in the  following swf; metal_mc, nonmetal_mc, metalloid_mc). I can make  individuals match to target areas (as there are tutorials for that) but i  want each one to be able to slide in to any target area (and someday i  want to create a solve button which will then place each element in the  correct place).
http://megaswf.com/serve/65365/
I  have started all over and have designated only chlorine to move (for  the moment) but how do i code it to allow it to fall into any of the  grey areas?
var objectoriginalX:Number;
var objectoriginalY:Number;
chlorine_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
chlorine_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
function pickUp(event:MouseEvent):void {
    event.target.startDrag(true);
function dropIt(event:MouseEvent):void {
    event.target.stopDrag();
chlorine_mc.buttonMode = true;
function pickupObject(event:MouseEvent):void {
event.target.startDrag(true);
event.target.parent.addChild(event.target);
objectoriginalX = event.target.x;
objectoriginalY = event.target.y;
(I would like to do it in AS3)
any ideas or other similar tutorials most appreciated.
many thanks,
sosodef

If you are not familiar with using the trace function, you should become familiar with it ASAP.  It is made for troubleshooting... it is your firend in finding things out.
If you place...
trace(event.target.dropTarget);
before your conditional line, you will see what you are actually looking at wrt the dropTarget.  Your code from yesterday is not what you just showed, it was...
if (event.target.dropTarget != null && event.target.dropTarget.parent == matchingTarget){
As for that first bit of code, remove it for now.  It is AS2 which will not work in an AS3 file, and the stuff inside the function is not legitimate code in any AS version.

Similar Messages

  • Drag and drop objects to multiple targets

    i have tried a lot of time to make my project into a success... However, it never work... i will be very appreciate with your kind help... please
    this is the link to my swf... all objects are accepted when i drop it into the plastic bin...
    http://megaswf.com/serve/77800/
    var startX:Number;
    var startY:Number;
    var counter:Number = 0;
    two.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    two.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    one.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    one.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    three.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    three.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    twotwo.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    twotwo.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    oneone.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    oneone.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    threethree.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    threethree.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    function pickUp(event:MouseEvent):void {
    event.target.startDrag(true);
    reply_txt.text = "";
    event.target.parent.addChild(event.target);
    startX = event.target.x;
    startY = event.target.y;
    function dropIt(event:MouseEvent):void {
    event.target.stopDrag();
    var myPlasticBin:String = "target" + "one" || "oneone" ;
    var myPlastic:DisplayObject = getChildByName(myPlasticBin);
    if (event.target.dropTarget != null && event.target.dropTarget.parent== myPlastic){
    reply_txt.text = "Good Job!";
    event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
    event.target.buttonMode = false;
    event.target.visible = false;
    event.target.x = myPlastic.x;
    event.target.y = myPlastic.y;
    counter++;
    } else {
    reply_txt.text = "Try Again!";
    event.target.x = startX;
    event.target.y = startY;
    if(counter == 6){
            reply_txt.text = "Congrats, you're finished!";
    three.buttonMode = true;
    one.buttonMode = true;
    two.buttonMode = true;
    threethree.buttonMode = true;
    oneone.buttonMode = true;
    twotwo.buttonMode = true;

    yup finally i have done with my problems!!! thanks ^^

  • Drag and drop Images into Multiple Targets

    Hello,
    I want to alter the NI example "Drag and Drop - Multiple Data Types to Start Drag" to use multiple image Targets.  The current VI only allows for dropping image into a single Target.  I want to duplicate the target window a few times, in order to drop different images into each different Target.  I can't seem to figure out how the VI recognizes and differentiates the Targets. 
    Thanks,
    Labview 2009 SP1

    Hello,
    Please see attached... That's a simple way to perform what you need : each target is handled in the same event case (the target is differentiated by using control refnum).
    Hope this helps,
    J.
    Attachments:
    Screenshot.jpg ‏132 KB

  • Target Area with Multiple Correct Choices

    I hope someone can help me with this issue.
    I am setting up a page that is going to be very interactive.
    I will give you one segment of the page. There will be a group of
    12 people (that have a certain job requirement) on the left and
    then on the right side there will be 7 different work areas for
    these people to work at. I want the user to drag 1 of the 12 people
    to certain areas and leave them. Up to this point it should be
    pretty straight forward, however, is gets more complicated....say I
    want 1 person to be dragged and only accepted at areas 1, 3 and 7
    but not at the other areas. How would I go about setting multiple
    target areas that would be correct?

    Well really it depends on how you are choosing to record the
    right
    answers and if you want to allow the user to put people in
    the wrong
    places. I dont think anyone will have the time to give you a
    complete
    run down on how to do all that without a fee but try looking
    at the
    active if field of the the target responses and set that to
    different
    icon titles.
    Jason Stewart
    logan3975 wrote:
    > Anyone? If this is not possible to set up, please just
    let me know so I can figure out another way to set this page up or
    if you need more details I am willing to give more.

  • Cannot drag and drop objects

    I starting having an issue with dragging/dropping objects on my screen a few days ago with my Macbook Pro. Say, for instance, there is a document on my desktop that I want to move to another location on my desktop or to a folder...when I left click on the document, a ghost of it appears on my cursor...I can move it around, but I cannot drop it. It takes several hits of the ESC key and clicks of the left mouse button to return the cursor to it's normal state, which also causes the ghost of the object to rush back to the original object icon instead of where I want to drag it. It does not matter if I use the touch pad on the laptop, my wireless house, or my wired mouse, which tells me it is a system issue and not a hardware issue. I am using 10.6.8. I have not voluntarily changed any mouse or desktop settings at all. I also noticed that when I move my cursor to the top left corner, it does not put the computer in a screensaver mode as I have it set up to do. I checked the screen settings and it is still set up to go to the screensaver when I move the cursor to that location. Does anyone know how to fix this?

    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It won’t solve your problem. Don’t be disappointed when you find nothing has changed after you complete it.
    Enable guest logins and log in as Guest. For instructions, launch the System Preferences application, select “Help” from the menu bar, and enter “Set up a guest account” (without the quotes) in the search box.
    While logged in as Guest, you won’t have access to any of your personal files or settings. Don’t be alarmed by this; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    As Guest, try the action. Same problem?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.

  • Captivate 8 Drag drop - Many to Many as correct answers? via type.

    Captivate 8 Drag drop - Many to Many as correct answers? i.e. via type grouping of drag image objects
    I've hit a brick wall. I've been testing this drag drop quiz feature via the Interaction Wizard and I've found that drag items assigned to the same type grouping, will only associate with one single target drop object. Is this a limitation of the drag drop wizard or a limitation of Captivate 8?
    I did successfully create a simple many to many drag drop when every drag item was unique, however when duplicating drag items and assigning them to the same type, it seems all the same type want to only have one single valid drop target.
    For example, creating an electronic circuit board quiz, I might have 3 resistors of the same value ( i.e. drag images of resistors ), that I want to be accepted by multiple drop targets ( i.e. rectangles that make up the circuit board ) that will accept a resistor drop item of that same value, as a valid drop item. In essence any of those 3 resistors of the same value, can be dropped in any of the circuit grid 3 cells and all still be correct. I can't seem to make this work, when those 3 resistor images are grouped into one type in the Drag drop Wizard. It only allows them to point to one drop container.
    Thanks,
    David

    Devraj,
    Actually I think I used your first method.   I had about 10 drag sources, some of the same type and some not and 25 drop targets of the same type to deal with.
    The approach I used was to group some of the Drag Source Objects ( like common parts such as multiple wire connector images, 4 in total ) but not group the Drop Target objects ( 25 rectangular shapes that make up the circuit board grid ). That did work successfully. I'm slowly getting to understand the way this drag and drop object type grouping works.
    My next test is to Group the Drop Targets by Drop type that can accept the corresponding Drag type. Thus for my 5 x 5 grid of rectangles objects, the drop rectangle objects that are designated for a given wire connector, would be assigned a drop type of that wire connector. If this can work, it could save even more time, when setting the correct answers. i.e. I would just set the correct answer as a drag type and drop type relationship. I think this could make it easier if I had a really big grid of drop rectangles, as I won't have to specify every single drag drop object relationship.
    Unfortunately so far this method is not working. I keep getting the Incorrect Answer message when testing, even though I know it's the correct drag drop answer. I know the drag source group type works, but the drop target group type is not working in the correct answer association with the drag group type.

  • 3 anspruchsvolle Fragen zu Drag&Drop in Adobe Captivate 8

    Leider komme ich bei drei Problemen nicht weiter und auch das Netz bietet keine zufriedenstellende Lösung.
    Frage 1
    Gibt es eine Möglichkeit, Zieh-Objekte beim Aufrufen des Quiz immer in zufälliger Reihenfolge/Anordnung aufzulisten?
    Frage 2
    Nachdem der User alle Ziehobjekte abgelegt und auf Submit geklickt hat, sollen die fehlerhaften Objekte rot umrandet werden. Wie geht das?
    (Ich meine keine typische pauschale Fehlereinblendung á la "Falsch!", sondern eine rote Umrandung des Ziehobjekts!)
    Frage 3
    Gibt es die Möglichkeit, nach dem 2. Versuch einen Button “Lösungen anzeigen” einzublenden? Bei Bei Klick auf diesen sollen die Ziehobjekte in die richtigen Ablegeboxen fliegen.
    Anbei eine Grafik, die das Ganze nochmal veranschaulicht.

    Devraj,
    Actually I think I used your first method.   I had about 10 drag sources, some of the same type and some not and 25 drop targets of the same type to deal with.
    The approach I used was to group some of the Drag Source Objects ( like common parts such as multiple wire connector images, 4 in total ) but not group the Drop Target objects ( 25 rectangular shapes that make up the circuit board grid ). That did work successfully. I'm slowly getting to understand the way this drag and drop object type grouping works.
    My next test is to Group the Drop Targets by Drop type that can accept the corresponding Drag type. Thus for my 5 x 5 grid of rectangles objects, the drop rectangle objects that are designated for a given wire connector, would be assigned a drop type of that wire connector. If this can work, it could save even more time, when setting the correct answers. i.e. I would just set the correct answer as a drag type and drop type relationship. I think this could make it easier if I had a really big grid of drop rectangles, as I won't have to specify every single drag drop object relationship.
    Unfortunately so far this method is not working. I keep getting the Incorrect Answer message when testing, even though I know it's the correct drag drop answer. I know the drag source group type works, but the drop target group type is not working in the correct answer association with the drag group type.

  • Windows Storage Server 2008 - unzip with drag & drop from Windows 7 client fails

    Hello.
    As i asked this question in German and got no answer so i try it in English now.
    I have the following problem:
    We have a Windows SBS 2008, where we store our files. If somebody opens a ZIP-file on a network share from a Windows 7 Client (64 Bit) it is possible to drag & drop the content (multiple files) to a directory. So far everything works as expected.
    We now have an additional Windows Storage Server 2008 integrated in our domain (Buffalo Tera Station WS-QV8/R5), where we also store files. If somebody opens the same ZIP-file on a network share of this server from a Windows 7 Client and tries to drag &
    drop the content the following happens:
    1. only one file is extracted and to display the file a refresh of the explorer view is needed.
    2. when the drag & drop action is repeated a second file is extracted
    Not alle files are extracted and there is no error message or indication why this happens.
    The behaviour is reproducible from another Windows 7 Client (32 Bit).
    If we try to drag & drop the files from the ZIP-file on the Windows Storage Server network sahre to a directory on the SBS network share all files are extracted correctly.
    On the Windows Storage Server itself all files are extracted without problmems. Therefore it must be a problem with the combination of Windows Storage Server und Windows 7 Client accessing the files via network shares.
    Are there any ideas where this problem could be located? Has anybody the same phenomenon and maybe a solution for it?
    Thanks in advance
    Michael Pruss

    Hi Michael,
    Thank you for clarifying the issue for us.
    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.
    Thank you for your understanding and support.
    Regards
    Kevin
    TechNet Subscriber Support
    If you are
    TechNet Subscription user and have any feedback
    on our support quality, please send your feedback here.
     

  • Drag & drop layer

    Hi,
    I would like to drag & drop a layer into a other document when document are viewed as tabs.
    I tried to drop the layer on top of the tab of another document, but it doesn't work. When in tab view mode, the only way is to copy and paste. But, I prefered when I can drag & drop layer, this way it keeps layer name.
    Is there a way to drag & drop layer on document that are displayed as tab?
    thanks for your help.

    You can do it in tabs mode. Just drag the layer to the destination tab, wait a minute, the tab will pop to the front and let you drag the layer over. The trick is that you must drag the layer from the document window (using the move tool), not the layer icon from the layers panel. If I am confused then it's the other way around (I don't use tabs).

  • Drag and Drop with multiple targets

    I'm having a problem find a solution to my drag and drop problem.  Here is what this flash piece is basically supposed to do:
    9 dragable items on the stage
    5 targets, numbers 1 - 5, where the items can be placed
    5 of the 9 dragable items are the correct answer and the user needs to drag them to the correct target, and have to be in order from 1-5. (eg. let's say the instructions are:
    Please place the, in the correct order, the 5 steps to getting ready in the morning
    Drag items                                               Targets
    Brush teeth                                       1.                     
    Change oil in car                                2.                    
    Wash face                                         3.                   
    Put pants on                                      4.                    
    Shower                                              5.                     
    Get out of bed  
    Do tax's
    So far I have it so if you drop the correct answer into its correct target it snaps to it and disable it's eventListeners.  If you drop the drag item on the other targets they snap to it and disable it as well.  They only problem is if the user accidentally drops the item anywheres else on the stage it locks it in place.  Instead I want it to return to the orginal x and y position.  Can anyone help?!?
    Here is my code
    DragDrop.as
    package
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.filters.DropShadowFilter;
    public class DragDrop extends MovieClip
      public var _targetPiece:*;
      public function DragDrop()
       this.addEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
       this.addEventListener(MouseEvent.MOUSE_UP, dropMovie);
       this.buttonMode = true;
      private function dragMovie(event:MouseEvent):void
       this.startDrag();
       this.filters = [new DropShadowFilter(0.5)];
       this.parent.addChild(this);
      private function dropMovie(event:MouseEvent):void
       this.stopDrag();
       this.filters = [];
      public function disable():void
       this.buttonMode = false;
       this.removeEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
       this.removeEventListener(MouseEvent.MOUSE_UP, dropMovie);
    DragGame.as
    package
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import DragDrop;
    import BL;
    import BR;
    import BM;
    import TL;
    import TR;
    import TM;
    import BC;
    import TC;
    import BA;
    public class DragGame extends MovieClip
      private var bl:BL;
      private var br:BR;
      private var bm:BM;
      private var tl:TL;
      private var tr:TR;
      private var tm:TM;
      private var bc:BC;
      private var tc:TC;
      private var ba:BA;
      private var _totalPieces:Number;
      private var _currentPieces:Number;
      private var _submit:Number;
      private var _reveal:Number;
      public function DragGame()
       _totalPieces = 5;
       _currentPieces = 0;
       createPieces();
       _submit = 6;
       _reveal = 1;
      private function createPieces():void
       bl = new BL();
       addChild(bl);
       bl._targetPiece = blt_mc;
       bl.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
       piecePosition1(bl);
       br = new BR();
       addChild(br);
       br._targetPiece = brt_mc;
       br.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
       piecePosition2(br);
       bm = new BM();
       addChild(bm);
       bm._targetPiece = bmt_mc;
       bm.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
       piecePosition3(bm);
       tl = new TL();
       addChild(tl);
       tl._targetPiece = tlt_mc;
       tl.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
       piecePosition4(tl);
       tr = new TR();
       addChild(tr);
       tr._targetPiece = trt_mc;
       tr.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
       piecePosition5(tr);
       tm = new TM();
       addChild(tm);
       tm._targetPiece = tmt_mc;
       tm.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
       piecePosition6(tm);
       bc = new BC();
       addChild(bc);
       bc._targetPiece = trt_mc;
       bc.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
       piecePosition7(bc);
       tc = new TC();
       addChild(tc);
       tc._targetPiece = trt_mc;
       tc.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
       piecePosition8(tc);
       ba = new BA();
       addChild(ba);
       ba._targetPiece = trt_mc;
       ba.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
       piecePosition9(ba);
      private function checkTarget(event:MouseEvent):void
       if(event.currentTarget.hitTestObject(event.currentTarget._targetPiece))
        event.currentTarget.x = event.currentTarget._targetPiece.x;
        event.currentTarget.y = event.currentTarget._targetPiece.y;
        event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, checkTarget);
        event.currentTarget.disable();
        _currentPieces ++;
        _submit --;
        if(_currentPieces >= _totalPieces)
         wrong_txt.visible = false;
         answer_txt.visible = true;
        if(_submit <= _reveal)
         submit_mc.visible = true;
         submit_mc.buttonMode = true;
       else
        event.currentTarget.x= event.currentTarget.dropTarget.parent.x;
        event.currentTarget.y= event.currentTarget.dropTarget.parent.y;
        event.currentTarget.disable();
        if(_submit <= _reveal)
         submit_mc.visible = true;
         submit_mc.buttonMode = true;
      private function piecePosition1(piece:*):void
       piece.x = 50.2;
       piece.y = 87.2;
       piece._origX = 50.2;
       piece._origY = 87.1;
      private function piecePosition2(piece:*):void
       piece.x = 50.2;
       piece.y = 109.2;
       piece._origX = 50.2;
       piece._origY = 109.2;
      private function piecePosition3(piece:*):void
       piece.x = 50.2;
       piece.y = 131.2;
       piece._origX = 50.2;
       piece._origY = 131.2;
      private function piecePosition4(piece:*):void
       piece.x = 50.2;
       piece.y = 153.3;
       piece._origX = 50.2;
       piece._origY = 153.3;
      private function piecePosition5(piece:*):void
       piece.x = 50.2;
       piece.y = 175.3;
       piece._origX = 50.2;
       piece._origY = 175.3;
      private function piecePosition6(piece:*):void
       piece.x = 50.2;
       piece.y = 197.3;
       piece._origX = 50.2;
       piece._origY = 197.3;
      private function piecePosition7(piece:*):void
       piece.x = 50.2;
       piece.y = 219.4;
       piece._origX = 50.2;
       piece._origY = 219.4;
      private function piecePosition8(piece:*):void
       piece.x = 50.2;
       piece.y = 241.4;
       piece._origX = 50.2;
       piece._origY = 241.4;
      private function piecePosition9(piece:*):void
       piece.x = 50.2;
       piece.y = 263.7;
       piece._origX = 50.2;
       piece._origY = 263.7;

    create an array of your droptargets (eg, droptargetA) and check if the object is dropped on a droptarget.  you don't even need the if-branch of the following if-else unless you do something that depends on whether the correct droptarget is hit.
    function checkTarget(event:MouseEvent):void
       if(event.currentTarget.hitTestObject(event.currentTarget._targetPiece ))
        event.currentTarget.x = event.currentTarget._targetPiece.x;
        event.currentTarget.y = event.currentTarget._targetPiece.y;
        event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, checkTarget);
        event.currentTarget.disable();
       else
    var x:Number=event.currentTarget.dropTarget._origX;
    var y:Number=event.currentTarget.dropTarget._origY;
    for(var i:uint=0;i<droptargetNum;i++){
        if(event.currentTarget.hitTestObject(droptargetA[i] )){
    x=droptargetA[i].x;
    y=droptargetA[i].y;
    break
    event.currentTarget.x=x;
    event.currentTarget.y=y;

  • 1 Success Caption for Multiple Targets in a Drag and Drop Interaction

    I see how I can add success captions to each target in a drag and drop interaction, but can you apply only 1 success caption multiple targets?

    The boundaries of smartshapes were overlapping with each other. For example, the smartshape on 1st line was overlapping with the one on 2nd line. Due to this, every time you place the text caption "Investment" on the smartshape on 2nd line, it automatically moved to the smartshape on 1st line. As a result, you could never get the answer right, and hence you never saw the Success Caption.
    Solution: Move the smartshapes away from each other (or resize them), and ensure that there are no overlaps.
    2,  The number of attempts for this interaction was set to Infinite. So, you have to play this until you get it right, but you could not get it right because of the reasons mention above. That is why you never saw the Failure Caption.
    Solution: Clear the Infinite check box in the Action accordion and specify the required number of attempts. You will get the Failure Caption if you don't get it right in those attempts.
    I just tested these solutions and they worked fine. Let me know if you still face any issues.

  • Drag and Drop objects to the same target

    Can any one assist? I have a box that has six labels that can be dropped on targets on the box. I have all this in place but I want to be able to have label 2 drop onto target 2 and 3, and likewise label 3 drop on to target 2 and 3. All others drop onto their specific targets. This is the script so far but ony for matching object to target. Please be gentle, i'm new to this!!
    event.target.stopDrag();
    var myTargetName:String="target" + event.target.name;
    var myTarget:DisplayObject=getChildByName(myTargetName);
    if (event.target.dropTarget!=null&&event.target.dropTarget.parent==myTarget)
    Can anyone assist please?

    What you could do is have an array assigned to each dragged item that defines the allowed targets for each dragged item and check if the dropTarget is in the array using the indexOf() method.

  • Issue with Drag/Drop of multiple rows from ListView

    I am working on a sample application with 2 list views i.e. players and team, and implement drop and drop such that players can be dropped from one list view to the other. Everything is working as expected when there is single selection model is enabled on the source list view. However, if I enabled Multiple selection model and drag 2 or more rows from source list view to target list view, seeing the following exception after the drop is completed.
    Exception:
    java.lang.IllegalArgumentException: Only serializable objects or ByteBuffer can be used as data with data format [subListPlayers]
      at com.sun.javafx.tk.quantum.QuantumClipboard.putContent(QuantumClipboard.java:513)
      at javafx.scene.input.Clipboard.setContent(Clipboard.java:230)
    1) What should be the DataFormat used in order to be able to drag and drop multiple rows? Looks like we do not have for Object type, so I have created the following one which does not solve the problem.
       private DataFormat dataFormat = new DataFormat("subListPlayers");
    2) I have made changes to support serialization on the data object which also does not seem to solve the issue. Tried by implementing Serializable interface as well as by implementing Externalize interface.
    Can someone please guide if there is an easy way to implement this behavior?
    Code:
    public class Player
       private String name;
       public Player(String name)
          this.name = name;
       public String getName()
          return name;
       public void setName(String name)
          this.name = name;
       @Override
       public boolean equals(Object o)
          if (this == o) return true;
          if (o == null || getClass() != o.getClass()) return false;
          Player player = (Player) o;
          if (name != null ? !name.equals(player.name) : player.name != null) return false;
          return true;
       @Override
       public int hashCode()
          return name != null ? name.hashCode() : 0;
    public class JavaFXDnDApplication extends Application
       private static final ListView<Player> playersListView = new ListView<Player>();
       private static final ObservableList<Player> playersList = FXCollections.observableArrayList();
       private static final ListView<Player> teamListView = new ListView<Player>();
       private static final GridPane rootPane = new GridPane();
       private DataFormat dataFormat = new DataFormat("subListPlayers");
       public static void main(String[] args)
          launch(args);
       @Override
       public void start(Stage primaryStage)
          primaryStage.setTitle("Drag and Drop Application");
          initializeComponents();
          initializeListeners();
          buildGUI();
          populateData();
          primaryStage.setScene(new Scene(rootPane, 400, 325));
          primaryStage.show();
       private void initializeListeners()
          playersListView.setOnDragDetected(new EventHandler<MouseEvent>()
             @Override
             public void handle(MouseEvent event)
                System.out.println("setOnDragDetected");
                Dragboard dragBoard = playersListView.startDragAndDrop(TransferMode.MOVE);
                ClipboardContent content = new ClipboardContent();
    //            content.putString(playersListView.getSelectionModel().getSelectedItem().getName());
                content.put(dataFormat, playersListView.getSelectionModel().getSelectedItems());
                dragBoard.setContent(content);
          teamListView.setOnDragOver(new EventHandler<DragEvent>()
             @Override
             public void handle(DragEvent dragEvent)
                dragEvent.acceptTransferModes(TransferMode.MOVE);
          teamListView.setOnDragDropped(new EventHandler<DragEvent>()
             @Override
             public void handle(DragEvent dragEvent)
    //            String player = dragEvent.getDragboard().getString();
    //            ObservableList<Player> player = (ObservableList<Player>) dragEvent.getDragboard().getContent(dataFormat);
                String player = dragEvent.getDragboard().getString();
                teamListView.getItems().addAll(new Player(player));
                playersList.remove(new Player(player));
                dragEvent.setDropCompleted(true);
       private void buildGUI()
    //      rootPane.setGridLinesVisible(true);
          rootPane.setPadding(new Insets(10));
          rootPane.setPrefHeight(30);
          rootPane.setPrefWidth(100);
          rootPane.setVgap(20);
          rootPane.setHgap(20);
          rootPane.add(playersListView, 0, 0);
          rootPane.add(teamListView, 1, 0);
       private void populateData()
          playersList.addAll(
                new Player("Adam"), new Player("Alex"), new Player("Alfred"), new Player("Albert"),
                new Player("Brenda"), new Player("Connie"), new Player("Derek"), new Player("Donny"),
                new Player("Lynne"), new Player("Myrtle"), new Player("Rose"), new Player("Rudolph"),
                new Player("Tony"), new Player("Trudy"), new Player("Williams"), new Player("Zach")
          playersListView.setItems(playersList);
       private void initializeComponents()
          playersListView.setPrefSize(250, 290);
          playersListView.setEditable(true);
          playersListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
          playersListView.setCellFactory(new Callback<ListView<Player>, ListCell<Player>>()
             @Override
             public ListCell<Player> call(ListView<Player> playerListView)
                return new ListCell<Player>()
                   @Override
                   protected void updateItem(Player player, boolean b)
                      super.updateItem(player, b);
                      if (player != null)
                         setText(player.getName());
          teamListView.setPrefSize(250, 290);
          teamListView.setEditable(true);
          teamListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
          teamListView.setCellFactory(new Callback<ListView<Player>, ListCell<Player>>()
             @Override
             public ListCell<Player> call(ListView<Player> playerListView)
                return new ListCell<Player>()
                   @Override
                   protected void updateItem(Player player, boolean b)
                      super.updateItem(player, b);
                      if (player != null)
                         setText(player.getName());

    Yeah, this is a pain. I filed https://javafx-jira.kenai.com/browse/RT-29082 a while back. Go ahead and vote for it if you are inclined...
    I think the issue in your case is that the observable list provided by MultipleSelectionModel.getSelectedItems() is not Serializable. So even if you make your Player class Serializable, the list itself isn't. The first thing I would try, I think, is to make Player implement Serializable and then pass in an ArrayList instead of the observable list. So you can do
    content.put(dataFormat, new ArrayList<Player>(playersListView.getSelectionModel().getSelectedItems()));
    and
    List<Player> player = (List<Player>) dragEvent.getDragboard().getContent(dataFormat);
    teamListView.getItems().addAll(player);
    If that doesn't work, a workaround is just to store the "dragged list" in a property:
    final ListProperty<Player> draggedPlayers = new SimpleListProperty<Player>();
    // Drag detected handler:
    content.putString("players");
    draggedPlayers.set(playersListView.getSelectionMode().getSelectedItems());
    // Drag dropped handler:
    if (dragboard.hasString() && dragboard.getString().equals("players")) {
         teamListView.getItems().addAll(draggedPlayers.get());
         draggedPlayers.set(null);

  • How to add text to a drag and drop object

    Hi everyone, I am quite a beginner with Flash so do excuse
    me. First, I am not sure if what I want to achieve may actually be
    impossible with Flash. I presently use MX 2004, but will shortly be
    upgrading to CS3. But if you know the answer for MX 2004 that would
    be really useful for now.
    I am writing a digital fiction story, and I want to create
    drag and drop objects. This I have managed to do. But I would like
    these drag and drop objects to also reveal text when they are
    actually pressed on. I have had no success so far in being able to
    achieve the two effects together.
    Does anyone know how I can achieve this? If, by chance, you
    know the action script that would be great. If you can explain to
    me in simple terms how I can achieve this I really would be
    grateful.
    Thanking you,
    Mary

    The script I posted would work on the main timeline - not in
    the timeline of the clip itself.
    So you made a movieclip out of the image and gave it the
    instance name "myclip". That's good.
    You edited that clip and added a dynamic text box with
    instance name "mytext". Be careful not to confuse the "instance"
    name of the text box with the "Var:" name. "myclip" should be the
    instance name. Also be careful to make sure you uncheck the
    "selectable" box. Edit your clip and click on the textbox to select
    it and look in the properties panel. There should be a button with
    Ab on it. If it is white background (highly likely), click it so it
    is not white. If the text is selectable, it will interfere with
    your button functions.
    While there is nothing wrong with creating nested clips
    within your movieclips, unless you plan to target them for
    something, there is no benefit. The only thing that needs an
    instance name inside the myclip is the textbox (based on what you
    are trying to do).
    You don't need any actionscript in the movieclip itself. If
    you can learn to place all your AS on the root timeline, you will
    be well ahead.
    If you placed that AS inside the clip, Flash wouldn't know
    what to do with it.
    Technically you can place the AS inside the clip on the layer
    you created but, if you did that, you would need to modify the
    script to the following:
    this.onPress = function() {
    this.mytext.text = "stop pressing so hard";
    startDrag(this);
    this.onRelease = function() {
    this.mytext.text = "";
    stopDrag();

  • Rollover text on a drag and drop object

    Hi folks, I wondered if someone could help me with this
    problem. Last week I was adding text to a drag and drop object on
    the press of a button and release of a button. This week, I am
    trying to get the drag and drop object to reveal text when the
    mouse rolls over it and again when the mouse releases it. I thought
    it should be pretty easy to fathom out the script for this, because
    I was given a lot of help last week. But I put in the attached
    code, and the object does not drag and drop, and neither does it
    show any text when the mouse rolls over it and off it.
    Can anyone tell me what I am doing wrong?
    Thanking you,
    Marchan

    The script I posted would work on the main timeline - not in
    the timeline of the clip itself.
    So you made a movieclip out of the image and gave it the
    instance name "myclip". That's good.
    You edited that clip and added a dynamic text box with
    instance name "mytext". Be careful not to confuse the "instance"
    name of the text box with the "Var:" name. "myclip" should be the
    instance name. Also be careful to make sure you uncheck the
    "selectable" box. Edit your clip and click on the textbox to select
    it and look in the properties panel. There should be a button with
    Ab on it. If it is white background (highly likely), click it so it
    is not white. If the text is selectable, it will interfere with
    your button functions.
    While there is nothing wrong with creating nested clips
    within your movieclips, unless you plan to target them for
    something, there is no benefit. The only thing that needs an
    instance name inside the myclip is the textbox (based on what you
    are trying to do).
    You don't need any actionscript in the movieclip itself. If
    you can learn to place all your AS on the root timeline, you will
    be well ahead.
    If you placed that AS inside the clip, Flash wouldn't know
    what to do with it.
    Technically you can place the AS inside the clip on the layer
    you created but, if you did that, you would need to modify the
    script to the following:
    this.onPress = function() {
    this.mytext.text = "stop pressing so hard";
    startDrag(this);
    this.onRelease = function() {
    this.mytext.text = "";
    stopDrag();

Maybe you are looking for