Solved

Drag and drop objects in Flash

Posted on 2007-04-09
6
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
SamuelRostol earned 500 total points
ID: 18875178
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
ID: 18875188
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
ID: 18875197
matter of few minutes..
:)
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 12

Expert Comment

by:SamuelRostol
ID: 18875553
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
ID: 18879372
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
ID: 18904763
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
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…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

751 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