Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Drag and drop objects in Flash

Posted on 2007-04-09
6
Medium Priority
?
429 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 2000 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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

670 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