Solved

Drag and drop objects in Flash

Posted on 2007-04-09
6
422 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
The goal of the tutorial is to teach the user how to how to record live broadcast.

627 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