Learn Flash Menus: Timeline ActionScript

Home Food Mates • Members Tutorials Forum Buy Templates Contact Us 

 


Flash Tutorials

   

Flash - Menu that Swings In

 

Free Flash Tutorial


Step 7    <<   Previous      Intro   1   2   3   4   5   6   7   8   9     Next   >>       >>   Webwasp Mates

 

Step Seven: ActionScript for the Timeline

The following Actionscript will make the first button move. There is additional code that makes the other buttons follow the first button, a bit like follow the leader.

  1. To avoid errors lock the Buttons Layer:
  2. Click on the Insert Layer button:
  3. Rename the new Layer to: Actions
  4. Place the following ActionScript on Frame 1 in the: Actions Layer

    // stops the movie on frame 1
    stop();

    // sets the x position for the menu to stop and go back to. You may need to adjust these two settings
    var goto = 30;
    var backto = -80;

    // declares a variable called go which will be used to help create the movement
    var go = 0;

    // sets the speed - don't set it too slow
    setInterval(mousePosition, 5);

    // this function is called by the word 'mousePosition' in the setInterval above
    function mousePosition() {
       // sets the x position for the mouse to activate the menu movement
       if (_xmouse<=20) { //adjust number as necessary
          MC1.
    _x = MC1._x+bounce("right");
       }
       
    if (_xmouse>=110) { //adjust number as necessary
          MC1.
    _x = MC1._x-bounce("left");
       }
    }

    // this function is called by 'bounce' in the mousePosition function above
    function bounce(leftOrRight) {
       // sets the swing properties
       if (leftOrRight == "right") {
          go = (goto-MC1.
    _x);
          go *= .09;
       }
       
    if (leftOrRight == "left") {
          go -= (backto-MC1.
    _x);
          go *= .09;
       }
       
    return go;
    }

    Note: If you are struggling to understand the functions above see the tutorial: Intro to functions

  5. Test Your Movie: Control > Test Movie (Ctrl + Enter)
  6. Place the Mouse over the: Menu bar


    So far only the first Button works.

    Note: Only one Button will work. To make the rest of the Buttons work there one more step.

  7. Close the Test Window:

         

Step 7    <<   Previous      Intro   1   2   3   4   5   6   7   8   9     Next   >>       >>   Webwasp Mates


Webwasp Community: Webwasp Mates & Dates

Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates

69677 visitors to this page since March 06 •

 Top of Page Home Food Mates Members Tutorials Forum Buy Templates Contact Us 
 All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.