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 :)
| » Level Advanced |
|
Added: 2000-06-28 Rating: 7 Votes: 185 |
| » Author |
| -- |
| » Download |
| Download the files used in this tutorial. |
| Download (16 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


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