Flash Tutorials Photoshop Tutorials Flash Games Flash Game Design
Create a Flash Website  
4) Actionscript for the Buttons
Step 25.
This is the final part of the tutorial to create a flash website. Next , in the "main mc", create a new layer called "script". Click on frame 1 of the layer and open up the actions panel.
 
Step 26.

Line 1 - This will stop the "sections" MC from looping repetedly

Line 2 - The speed at which the yellow rectangle scroll

Line 3 - The target Y position for the yellow rectangle is set to button1's Y position

 
Step 27.

Line 4 - Rather that write each button function individually, a for loop is created to loop through each button and assign an onPress function to it. The "i" in the loop will start off at 1 and increment by 1 (i++), while i is below 5(i<5). If we had 10 buttons we would set this to i<11.

Line 5 - Each button is refered to using this["button"+i]. The For loop increments "i", so each button will be referenced. On this line a page number (pageNum) property is assigned to each button, using "i". Button1 will be assigned the pageNum "1", button2 "2" and so on.

Line 6 - An onPress function is assigned to each button.

Line 7 - When the any of the buttons is pressed the target variable is to the position of the button (this._y).

Line 8 - Content mc is told to go to the page number that was stored, on line 5, in the pageNum property.

 

 
Step 28.

Line 11 - An onEnterFrame function is created which will execute any code inbetween the braces {} repetedly, at the frame rate of the movie.

Line 12 - This is the code used to move the "current" MC to the "target" value, whenever a button is pressed.

 

 
Step 29. Entire Code
 
 
And that's all the Actionscript that needs to be written to create the flash website! Download FLA
Part: 1 | 2 | 3 | 4 |
 
More Flash Tutorials
 
 
   
     
     
 
Navigation
Flash Tutorials
Photoshop Tutorials
Flash Games
War Games
 
 
 
 
 
 
 
Top Flash
Create a Spot the Difference Game
Create a Shooter Game
Flash Gallery Tutorial
Flash Website Tutorial
Flash Glitter Graphic
 
 
 
 
 
 
Game Websites
Happy Wheels
Tower Defense Games
Hunting Games
Mario
 
 
 
 
 
 
 
 
     
Site Copyright © 2006 - 2011 Nick DS. All rights reserved.