Solved

Drag and drop objects in Flash

Posted on 2007-04-09
6
382 Views
Last Modified: 2010-04-03
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?
http://www.sorbose.com/sample_75_games/make_faces.swf

Any ideas

Seb
0
Comment
Question by:sebastiz
  • 3
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
SamuelRostol earned 500 total points
Comment Utility
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() {
     this.startDrag();
}
mc_clip.onRelease = function() {
      stopDrag();
}

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

Good luck!
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
Comment Utility
yes, it has actionscript functions:

to drag a movieclip, use following code:
==========
square_mc.onPress = function() {
    this.startDrag();
};
----------------------

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

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

- Aneesh Chopra


0
 
LVL 34

Expert Comment

by:Aneesh Chopra
Comment Utility
matter of few minutes..
:)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 12

Expert Comment

by:SamuelRostol
Comment Utility
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 :)
0
 
LVL 37

Expert Comment

by:CyanBlue
Comment Utility
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...

CyanBlue
0
 
LVL 12

Expert Comment

by:SamuelRostol
Comment Utility
Ok, thanx :)

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now