Skip navigation
Windbutnu
Currently Being Moderated

Drag & Drop interaction in Flash CS5

Mar 23, 2013 12:37 AM

Tags: #drop #cs5 #flash #& #in #interaction #drag

I have created 2 squares, a small and a big one, I want the user to be interactif with the first square, meaning, when the user make a left click and hold on, he should be able to move that square then placed in the bigger one, like a regular drag and drop movement. can somebody please help me?

 
Replies
  • Currently Being Moderated
    Mar 23, 2013 4:38 AM   in reply to Windbutnu

    Using AS3 it would be something like:

     

    smallSquareName.addEventListener(MouseEvent.MOUSE_DOWN, dragSmallSquare);

     

    function dragSmallSquare(evt:MouseEvent):void {
         addChild(MovieClip(evt.currentTarget)); // to place above other content
         evt.currentTarget.startDrag();
         stage.addEventListener(MouseEvent.MOUSE_UP, dropSmallSquare);
    }

     

    function dropSmallSquare(evt:MouseEvent):void {
         stopDrag();
         stage.removeEventListener(MouseEvent.MOUSE_UP, dropSmallSquare);
    }

     

     

    The names I used for the square and the functions can be changed to whatever you like.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 23, 2013 2:54 PM   in reply to Windbutnu

    First make sure you have a movieclip object on the stage that you intend to be the small square.  Click on it to select it and enter the name you want to give it where it says <Instance Name> in the Properties panel (my code would have me naming it smallSquareName).  That is about all you'll need for starters for the code to work.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 24, 2013 5:18 AM   in reply to Windbutnu

    Your logic sounds fine.  Follow thru with implementing it and if you run into a problem start a new posting.  Since you have C++ under your belt, the only issue you should have is determining how to do the same with AS3... it's just another programming language.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points