A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11303 Flash Movies | 7 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Nitin Tikhe
» Title: Cart
» Description: This Animation Tut is a fun and useful for kids below 15 years. Watch the Flag, Doors, Stick and Horse movements.
» More by Nitin Tikhe


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 6008 Flash Sites | 0 New Flash Links
What's New | Top 100 Flash Site

Featured Site

» Posted in the Flash Kit Links section
» Title: Banana Swimwear
» Description: This is a banana swim wear interactive catalog we designed and animated in Flash


Random Links | Add your own Flash Related Links
Flash Tutorials 1255 Tutorials 7 New Tutorials Added!
What's New | Top100

» Make flash video player for broadcasting live streaming video / TV on website
» How to convert the project file of Flash Demo Builder 2.0 into FLV file
» FLV to PSP for Mac - How to convert YouTube video to PSP on mac
» How to Convert FLV to MP4 for Playback on iPod
» how to download and convert youtube video to AVI with Leawo Free FLV converter
» Flash Multi-player Game Tutorial - TicTacToe
» How to make Flash elearning tutorials with screen recorder?
» Fader API:Slideshow with MovieClips on stage
» How to convert MS PPT file into an FLV File
» Unknown Tag: Title10
Random Tutorial | Add Site

Network Design Manager
The Computer Merchant, Ltd
US-VA-Hampton

Justtechjobs.com Post A Job | Post A Resume


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Actionscripting

Categories Drag, Drop and Swap
Author: Gorky

 
Page 5
«prev 1 2 3 4 5 6 7 next»

On (Press)
 Set Variable: "/:current_targetX" = GetProperty ("", _x)
 Set Variable: "/:current_targetY" = GetProperty ("", _y)
 Set Variable: "/:ballnum" = 1
 Call ("/code:OnPress")
 Start Drag ("", L=45, T=45, R=455, B=255)
End On
On (Release, Release Outside)
 Call ("/code:OnRelease")
 Stop Drag
End On

The basic action here is the drag action, which is accomplished using the Start Drag command on a mouse action. Before we start the drag, we assign the 'current_target' variables contained in the last piece of code to the current x and y loc of the ball we just click on. We also set the ballnum variable to 1, which is the number of the ball we just clicked on. Depending on which movie clip you are putting this code into, change this number the number of that movie clip. For example, when you put this code into movie clip 4, then you will set 'ballnum' to 4. After 'ballnum' is set, the OnPress code is called. Here it is.

Set Variable: "/:first" = eval("/:ballpos" & /:ballnum)
Set Variable: "num" = 0
Loop While (num <= 6)
 If (/:ballnum <> num)
 Set Property ("/ball" & num, Visibility) = 0
 End If
 Set Variable: "num" = num + 1
End Loop

The first line sets the 'first' variable to the same number as ballpos1 (or ballpos2, whichever ball you are dragging). A quick word on the ballpos variable. Its not very intuitive, but ballpos1 = 4 means that ball1 is on the 4th target. ballpos5 = 3 means ball 5 is on the 3rd target etc. What the 'first' variable does basically is to store which target you are pulling your dragable movie clip from. So if you begin dragging ball 3 from target 6, first gets set to 6. As you saw in the initialization code, ballpos1 - ballpos6 all get set to 1-6 initially.

The loop contained in this part of the code sets ball1 through ball6 (except the one you are dragging) invisible.

Here is where I need to explain why I have two sets of dragable movie clips, and the need for the loop just described. Basically, its all for looks. If we take away the stayers layer, and remove the previous loop from the movie, it will all still work except that when you go to drag one of the movie clips, many of them will appear beneath the other ones when dragged across them. Each movie clip has its own depth even though they are all on the same layer, and since you can't change depth in actionscript, the only way I could figure out how to always make them appear on top of all the other ones when you are dragging them is to do it this way.

So now, when you start dragging a movie clip, all the other movie clips on that layer disappear, but you don't see it since there are duplicates of those clips on the stayers layer. Since all the movie clips except the one you are dragging (on the 'draggers' layer) are now invisible, the one you are dragging will never appear to be behind anything. If you don't know what I mean, delete the stayers layer, remove this loop from OnPress, and remove the loop that turns the visibility back on (this loop is in OnRelease), then run it and drag some stuff around. If anyone knows a simpler way to do this I would appreciate the knowledge :)


«prev 1 2 3 4 5 6 7 next»

» Level Advanced

Added: : 2000-06-28
Rating: 7.00 Votes: 181
Hits: 14049
» Author
--
» Download
Download the files used in this tutorial.
Download (16 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments