First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing! | Flash Jobs
Search tutorials
Author: Gorky | Website: http://

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 <%lt%> /: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).


» Level Advanced

Added: 2000-06-28
Rating: 7 Votes: 185
(10 being the highest)
» Author
--
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.