Donate
 
Has KnowFlash helped you?

Donate towards running costs:


Why donate?

Newsletter
Sign up to our newsletter:
 
Enter your email address:
 
flash menu
Tutorials
Video Tutorials
Store
Main Menu
Home
News
Forum
Help/FAQ's
Contact Us
Search
Register
Advertise
Links
Webmasters

Drag And Drop Items Print E-mail
Written by Rawpulse   
Thursday, 23 February 2006
Learn how to drag and drop items in Flash!
 

Introduction


Dragging and dropping is used everywhere. Not only in general file moving and placing, but also within games. It my be necessary to move a certain item elsewhere for a puzzle or adventure game. We're going to take a look at the basics of dragging and dropping in Flash. It is a very simple effect to conquer. It only requires a few lines or Actionscript to work, and I shall explain what the Actionscript is telling Flash to do. If you would like to see an example of what you can create, click here.


Stage 1


Before you draw anything set your background color to a nice dark shade. Also set your frame rate to 35. Start off by drawing an item or importing an image into Flash. This will be the item we will drag. In this tutorial, we will be making some text draggable. Once you have imported/typed/drawn your item, convert it to a symbol by selecting it and pressing F8. Make sure it is a movie clip, and press ok.


Stage 2


Draw a box where you want the user to drag the item to. If you just want to be able to drag the item randomly, do not draw a box. At this stage, you should have something that looks like this:





As you can see, we have the text "KnowFlash" which is converted to a symbol. We also have a box with the ".com" part, so when the text is dragged and placed into the box, "KnowFlash.com" will be seen.


Stage 3

We now need to make the text actually draggable. To do this, we use a small amount of Actionscript, which we add to our movie clip. Select it, press F9 to bring up your Actions panel and add the following code:


on(press) {
startDrag(this,false);
}

on(release) {
stopDrag();
}


This tells Flash to begin dragging the symbol once it has been pressed with the mouse button. It then says on release (when the mouse button is released, after it has been dragged), stop the dragging. If you test your movie now, by pressing Control + Enter, you should be able to drag your item around the stage. As mentioned previously, this has many uses. Click here to see an example of how it could be used within a game. (Drag the gun and grenade into your Inventory).

If you have had problems with this tutorial, tell us about it on the KnowFlash forum.


Last Updated ( Thursday, 23 February 2006 )
< Prev

In association with Coursework Essays , Free Essays , Phishing Scams and Big Red Directory

Copyright Oxford Information Services Ltd 2007