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 Miguel Panos
»  Title: Tarta
»  Description: It is a circle graph or pie chart that takes the data entered by user
»  More by Miguel Panos


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

Featured Site

»  AuthorDeft Creative Ltd
»  Link: Home Page
»  Description: Portfolio site for .DeftCreative Ltd. A UK based web design studio specialising in flash websites, games and interactive CDROMs. With an emphasis on making things different.


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

» Making Automatic Training Screen Capture Easily
» Create Undersea Life Animation
» Making Deinterlace Video with a low bitrate Easily
» 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
» Unknown Tag: Title10
Random Tutorial | Add Site


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

Search Tutorials


Tutorials Tutorials » Games

Categories Advanced movement in Flash 4.
Author: Gnomish Nation | Website: http://ilovegnomes.tripod.com/ |

 
Page 1
1

Part 1: Movement

Step 1: Create a simple object, like a dot. Convert it to a movie clip, naming it whatever you want. Give it an instance name of “dot.”
Step 2: Right Click and Edit the dot. On it's first frame, give it the action “Stop.”
Step 3: On it's second frame, copy in this code: (You don't have to copy the comments)
Comment: Set the position of our dot.
Set Variable: “x” = GetProperty(“”,_x)
Set Variable: “y” = GetProperty(“”,_y)
Comment: Set the position of a dragged object (we will create the object later)
Set Variable: “x2” = GetProperty(“/drag”,_x)
Set Variable: “y2” = GetProperty(“/drag”,_y)
Comment: Get the distance between the dot and the dragged object
Set Variable: “xdist” = x2-x
Set Variable: “ydist” = y2-y
Comment: This is the trickiest part. The dot is going to move at 5 pixels every frame until it reaches the object called /drag. We are checking to see how close it is, so the if the object is less than 5 pixels away, we don't want the dot to move over it.
If ((xdist <5 AND xdist> -5))
 Set Variable: “xmove” = xdist
Else
 Set Variable: “xmove” = 5
 If (x2 -5))
 Set Variable: “ymove” = ydist
Else
 Set Variable: “ymove” = 5
 If (x2 -5))
 Set Variable: “xmove” = xdist
Else
 Set Variable: “xmove” = 5
 If (x2 -5))
 Set Variable: “ymove” = ydist
Else
 Set Variable: “ymove” = 5
 If (x2x2 OR GetProperty("",_y)<>y2)
 GoToAndPlay(3)
Else
 GoToAndStop(1)
End If
Step 6: Now you're finally finished with the dot/character! Now, create another dot and convert it to a symbol. Give it a name, and give it's instance the name “drag.”
Step 7: Edit the new dot, and give it one action on its first frame:
Comment: This object will follow the mouse.
StartDrag(“”,lockcenter)
Step 8: Now go back to the movie and right-click the new dot. Click “Properties.”
Step 9: Go to “Color Effect,” select “Alpha,” and drag the slider to 0.
Step 10: Close the properties window and create a rectangle that convers the entire movie. Fill it with any color you want.
Step 11: Convert the rectangle to a symbol. Call it whatever you want, and be sure to convert it into a button symbol this time.
Step 12: Open the button properties, click the Actions tab, and insert this code:
On(Press)
 Comment: This will make the dot move.
 Begin Tell Target(“/dot”)
 Play()
 End Tell Target
End On
Step 13: If you haven't already, place all three objects in the movie. Put the first dot somewhere in the middle, the second anywhere you want, and the rectangle so it covers the movie screen. Set the rectangle's alpha to 0. Test your movie.
Step 14: Click anywhere and the dot should move to your cursor. This is a more advanced way of moving than using arrow keys.

PART 2: Collision

Step 15: Draw an object. It can be a tree, a wall, a square. Make it about four times as big as the first dot you drew.
Step 16: Convert your work of art into a movie clip. This time it doesn't need an instance name. Just right-click and edit.
Step 17: In the first frame, insert this code:
Comment: Get my position
Set Variable: “x” = GetProperty(“”,_x)
Set Variable: “y” = GetProperty(“”,_y)
Comment: Get the dot's position
Set Variable: “x2” = GetProperty(“/dot”,_x)
Set Variable: “y2” = GetProperty(“/dot”,_y)
Comment: Do some math to get the positions of my sides.
Set Variable: “top” = y-(GetProperty("",_height)/2)
Set Variable: “bottom” = y+(GetProperty("",_height)/2)
Set Variable: “left” = x-(GetProperty("",_width)/2)
Set Variable: “right” = x+(GetProperty("",_width)/2)
Comment: Check to see if the dot has collided with me. Push it away if it has.
If (x2>= left AND x2 <= right AND y2 <= top AND y2>= top – 10)
 Set Property (“/dot”,_y) = top-10
End If
If (x2>= left AND x2 <= right AND y2>= bottom AND y2 <= bottom + 10)
 Set Property (“/dot”,_y) = bottom+10
End If
If (y2>= top AND y2 <= bottom AND x2 <= left AND x2>= left – 10)
 Set Property (“/dot”,_x) = left-10
End If
If (y2>= top AND y2 <= bottom AND x2>= lright AND x2 <= right + 10)
 Set Property (“/dot”,_x) = left-10
End If
Step 18: Now for the object's second frame, put in this code:
GoToAndPlay(1)
Step 19: Go back to the movie and make several copies of this object. Scatter them around.
Step 20: Test the movie. Walk around a little, then try to walk through one of these squares. See what happens?


1

» Level Intermediate

Added: : 2005-01-04
Rating: 3.55 Votes: 9
Hits: 435
» Author
Teaches how to move characters by clicking and how to make objects that the character can collide with.
» Download
Download the files used in this tutorial.
Download (4 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