The place that has your tutorials

Movement + Rotation In Flash

July 29th, 2007

Have you seen these flash space games where you can move and rotate a spaceship. well here is how to do it.

1- Load up flash MX and set the document size to 550 by 400. to do this go to modify>document.

2- create a spaceship what ever you want it to be.

3- select it and press on F8 select movieclip and the press ok.
Press on the spaceship now and load up the actions panel by going to windows>actions. make sure it says Actions-Movie clip not Actions-frame.
add the following in the actions box:

Actionscript:
  1. onClipEvent (load) {
  2. thrust = 1; //sets speed
  3. decay = 1;//sets strenght not needed at the moment
  4. maxSpeed = 15;//maximum speed
  5. }
  6. onClipEvent (enterFrame) {
  7.  
  8. if (Key.isDown(Key.RIGHT)) { //if right button is down
  9. _rotation += 10; //rotate 10 degreese clockwise
  10. }
  11. if (Key.isDown(Key.LEFT)) { //if left button is down
  12. _rotation -= 10; //rotate 10 degreese anti-clockwise
  13. }
  14. if (Key.isDown(Key.UP)) {//if up button is down
  15. xSpeed += thrust*Math.sin(_rotation*(Math.PI/180));
  16. ySpeed += thrust*Math.cos(_rotation*(Math.PI/180));
  17.  
  18. } else {
  19. xSpeed *= decay;
  20. ySpeed *= decay; //slow down
  21.  
  22. }
  23. speed = Math.sqrt((xSpeed*xSpeed)+(ySpeed*ySpeed));
  24. if (speed>maxSpeed) {
  25. xSpeed *= maxSpeed/speed;
  26. ySpeed *= maxSpeed/speed;
  27. }
  28. _y -= ySpeed;
  29. _x += xSpeed;
  30.  
  31. //make the ship come back on screen if it goes out of view
  32. if (_y<0) {
  33. _y = 400; // document height
  34. }
  35. if (_y>400) {
  36. _y = 0;
  37. }
  38. if (_x<0) {
  39. _x = 550; //document width
  40. }
  41. if (_x>550) {
  42. _x = 0;
  43. }
  44. }

test the movie by clicking control+ enter
That should do the job neatly. If you have any problems or errors coming up please do not hesitate to contact me.


Making an Simple mouse follower

July 29th, 2007

1- Draw what ever you want to follow the mouse.
2- Select it and press F8 make it a movie clip.
3- Click on the new movie clip
4- load up the actions panel from windows>action

insert the following

Actionscript:
  1. onClipEvent (load) { //when the movie loads
  2. Mouse.hide(); //hide the mouse
  3. startDrag("", true);//start to follow the mouse.
  4. }

press control and enter to test it.

What do you think.
If you have any problems please don't hesitate to ask.


Basic Buttons

July 29th, 2007

1- Load up flash
2- draw a rectangle
3- select it
4- press F8
5- Select button
6- Press OK
7- select it
8- go to windows>actions
9- enter the following

Actionscript:
  1. on (release) { // means when pressed
  2. getURL"http://www.yoursite.co.uk"); //www.yoursite.co.uk); //go to this url [b]must have the http://www. part[/b]
  3. }

10- right click on the button and press edit
11- you now see the states of a button
12- right click on each of the states and press insert a keyframe
14- change the colour of the rectangles.
15- test the movie by clicking control+ enter by clicking on the rectangle.
16- see what happens

If you have any problems please do not hesitate to contact me.


Search Page

July 29th, 2007

OK This tutorial will show you how to make a search page.

Firstly we make a form. I am going to use this:

HTML:
  1. <form method="post" action="searchpage.php">
  2. <p>Please enter keyword.</p>
  3. <input name="word" type="text" size=25 maxlength=25>
  4. </p>
  5. <input type="Submit" name="Submit" value="Submit">
  6. </p>
  7. </form>

This is the form where we will enter the keywords. Now the next step is to make the searchpage.php.

It will look like this

PHP:
  1. <?php
  2. // connect to db
  3. $db = mysql_connect("localhostt", "username", "password");
  4. mysql_select_db("dbname",$db);
  5.  
  6. //check something is sent
  7. if ($_POST['word']) {
  8. $word= $_POST["word"];
  9. // search query
  10. $result = mysql_query("SELECT * FROM `table` WHERE `field` LIKE '%$word%'");
  11. $postword = $_POST['word'];
  12. echo "Search Results for: <strong> $postword </strong> <br />";
  13. echo"<p> </p>";
  14. echo"<p> </p>";
  15. echo"<p> </p>";
  16. echo"<p> </p>";
  17. //get results
  18. while($get=mysql_fetch_array($result))
  19. {
  20.  
  21.  
  22. $date = $get['date'];
  23. $name = $get['name'];
  24. $title= $get['title'];
  25.  
  26. //show results
  27. echo("<strong>$title</strong> was added on <strong>$date</strong> by <strong>$name</strong>");
  28.  
  29. echo"<p></p>";
  30. echo"<p></p>";
  31. }
  32. // if nothing is sent
  33. }else {
  34. die ("No search word specified");
  35. }
  36.  
  37. ?>