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 6
«prev 1 2 3 4 5 6 7 next»

Up to now, all we have done is click on a ball and begun to drag it, now we will see what happens when we drop it. As you can see from the On Release action, when the mouse is released, the movie clip calls some code called OnRelease. Here is what that code says.

Set Variable: "found" = false
Set Variable: "count" = 0
Loop While (count <= 6 )
 Set Variable: "count" = count + 1
 If (GetProperty ("/ball" & /:ballnum, _droptarget) eq "/target" & count and
 GetProperty ("/ball" & /:ballnum, _droptarget) ne "/target" & eval("/:ballpos" & /:ballnum))
 Set Property ("/ball" & /:ballnum, X Position) =
 GetProperty ("/target" & count,  _x)
 Set Property ("/ball" & /:ballnum, Y Position) =
 GetProperty ("/target" & count,  _y)
 Set Property ("/balla" & /:ballnum, X Position) =
 GetProperty ("/target" & count,  _x)
 Set Property ("/balla" & /:ballnum, Y Position) =
 GetProperty ("/target" & count,  _y)
 Set Variable: "/ball" & /:ballnum & ":current_targetX" =
 GetProperty ("/target" & count,  _x)
 Set Variable: "/ball" & /:ballnum & ":current_targetY" =
 GetProperty ("/target" & count,  _y)
 Set Variable: "/:last" = count
 Set Variable: "/:ballpos" & /:ballnum = count
 Set Variable: "found" = true
 Call ("/code:CheckResidents")
 Call ("/code:Swap")
 Else If (found ne true)
 Set Property ("/ball" & /:ballnum, X Position) = /:current_targetX
 Set Property ("/ball" & /:ballnum, Y Position) = /:current_targetY
 End If
End Loop
Set Variable: "num" = 0
Loop While (num <= 6)
 If (/:ballnum <> num)
 Set Property ("/ball" & num, Visibility) = 1
 End If
 Set Variable: "num" = num + 1
End Loop

This is basically two loops. The second loop sets our visibility back to 1 for all the other movie clips after the first loop is run, but the first loop is the main one here. That first if statement is pretty long so let me put it in English.

If the place you just dropped the ball onto equals a target area, and that target area is not the target you just dragged from then...

If this condition is met then the lines following set the ball you just dropped to the same location as the target area you just dropped on. It also sets balla to that same location, so each instance of that movie clip are moved. If the condition is not met, the ball will snap back to its original location (which gets set when you click on it). In addition if the first condition is met there are three other variables that are set, and two more pieces of code that are called. The variable last gets set to the target number you just dropped on (so now we have first and last which are the two target numbers we moved from and to). ballpos1 (or ballpos2, whatever) gets set to the same thing that first gets set to, the target number (so now ballpos1 will equal 3 or whatever target you dropped it onto meaning that ball1 is now in the 3 position). The last thing that gets set is a found variable. This is so the else if statement will work. In other words, if the first condition is met and found gets set to true, then the else if will not run. To be honest I don't know why we can't just have 'else' instead of 'else if' and do away with the found variable, but it doesn't work right if we change it like that. If anyone knows why I would like to know.

Now let's go look at the two functions that get called in that last loop. First, here is CheckResidents

Set Variable: "num" = 0
Loop While (num <= 6)
 If (Eval ("/:ballpos" & num) = /:last)
 Set Variable: "/:resident1" = num
 End If
 Set Variable: "num" = num + 1
End Loop
Set Variable: "num" = 0
Loop While (num < /:resident1)
 If (Eval ("/:ballpos" & num) = /:last)
 Set Variable: "/:resident2" = num
 End If
 Set Variable: "num" = num + 1
End Loop
Stop

What these loops do is find both the number of the movie clip that was just dragged and the number of the movie clip that was already sitting on the target we just dropped on. The first loop will run through and assign resident1 to the first movie clip (the highest number out of six) and the second loop will start at 0 and go up to the first number found, locating the second number and assigning it to resident2. Maybe it makes more sense this way. Each loop takes the target that was just dropped on and compares it to the location of every movie clip. Along the way it find two movie clips whose location are equal to that target, and it assigns resident1 and resident2 to each of those movie clips number. So if a target contains ball1, and we drop ball3 on it, resident1 gets set to 3(ball3) and resident2 gets set to 1 (ball1).


«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