Solved

Drag and drop objects in Flash

Posted on 2007-04-09
6
401 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
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to put actionscript code for a button? 6 129
Dreamweaver FTP Access 12 89
free webina streaming recording software 5 95
Application.cfc - what is the order of events? 4 30
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…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

770 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