Internet Commerce

Partners & Affiliates

Developer Channel


Featured Flash FLA
Gallery Downloads 11401 Flash Movies | 5 New Flash Movies Added
What's New | Top 100

Featured FLA

»  Author: Nick Kouvaris
»  Title: Znax
»  Description: Znax is a board game. Click 4 tiles of the same color and form squares as big as you can. You will erase all the tiles inside the square and collect points. Get maximum score if you make a square with game edges.
»  More by: Nick Kouvaris


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

Featured Site

»  Author Agence WOP Digital Agency
»  Title: Electricdrum
»  Description: French WOP Agency, 3D websites, Flash (Papervision, Away 3D), event or institutional projects. The agency operates on all digital projects: consulting, design, graphic design, development, online communication. The WOP agency follows you on the implementation of original, creative and optimized digital projects.


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

» How To Make A Simple Animation Using Christmas Clips
» Simple Step by step flash game tutorial Spot the diffrence
» How To Make A Moving Text Slide
» Create Flash Banner With Text Float Effect
» How To Make Zoo Photos Slideshow
» How To Make A Dolphin Photos Slideshow
» How To Make A Fathers Day Slideshow
» How To Make A Transparent Background of Your Flash File
» Create Flash Banner With Text Disco Light Effect Today we will introduce you a Text Disco Light eff
» Unknown Tag: Title10
Random Tutorial | Add Site


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.07 Votes: 186
Hits: 14054
» 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