Drag and drop objects in Flash

Using Macromedia Flash MX 2004
I would like to know how to drag objects around the screen in flash MX in the same way as is done in this page. Is this an actionscript function, or does it come as a behaviour?

Any ideas

Who is Participating?
SamuelRostolConnect With a Mentor Commented:
Hi there :)

It's not that diffiult really. Create a clip, convert it to a movieclip, and give it a instance name (instance name is created in the properties panel at the bottom of the screen when the movieclip is selected).
Give it the instance name "mc_clip".

Then, create a new layer, name it "actions", and write the following code in it:

mc_clip.onPress = function() {
mc_clip.onRelease = function() {

This is the basic code needed for that drag/drop application :) Just copy the code to all the other clips as well :)

Good luck!
Aneesh ChopraCommented:
yes, it has actionscript functions:

to drag a movieclip, use following code:
square_mc.onPress = function() {

and on mouse release, stop the dragging and check if object being dragged hit the required object:

square_mc.onRelease = function() {
    if (this.hitTest(circle_mc)) {
      // code if hits the required movieClip
     // code if does not hit the required movieClip

- Aneesh Chopra

Aneesh ChopraCommented:
matter of few minutes..
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Hehe, been there done that :)

By the way, stopDrag is a global function, not a movieclip property, so you don't need to use 'this' in front of it

stopDrag(); is sufficient :)
startDrag()/stopDrag() are both global function and the public methods of the MovieClip class at the same time...  
So, you can use either stopDrag() or this.stopDrag() and both should work as it is supposed to be...

Ok, thanx :)

My meaning was just that stopDrag will ALLWAYS stop a drag initiated by startDrag, so the prefix 'this.' will not do anything ;-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.