Home Flash Tutorials
Flash ActionScript Tutorials PDF Print E-mail
Written by Geoff Hill   
Thursday, 01 April 2010 09:07

Geoff's tutorials target beginners to Flash Actionscript. They assume no prior knowledge of programming but do expect the learner to be familiar with the flash interface. Learners should also know about and how to create the following flash symbols:

  • graphics
  • buttons
  • movie clips

Programming Basics

Before beginning the tutorials it is important that the learner understands the basic constructs of programming, about variables that can be used to store information or changing values and functions that perform a specified task. As the tutorials become more complex, the learner will be introduced to other programming concepts

All computer programs and programming languages use three basic constructs.

  • Sequence - things that happen step by step
  • Selection - things the happen based on a true or false condition
  • Iteration (loops) - things that continue to happen until a condition changes

Sequence

When a program has to follow a number of steps in the correct order, this is called a sequence.

Example:
Ask a person for their first name.
Ask a person for their last name.
Display the person's first name and last name separated by a space.

Selection

When a program has to test if a condition is true or false this is called selection or an IF then ELSE statement.

Example:
Pick a random number.
Ask the user to guess the number.
IF the guess is equal to the number THEN
Display "You Got It!"
ELSE
IF the guess is lower than the number THEN
Display "Too Low"
ELSE
IF the guess is higher than the number THEN
Display "Too High
END IF

Iteration (Loop)

Anytime a program has to continue a number of steps until a condition changes, this is called a loop. The two most common forms are a WHILE and FOR loop.
WHILE loops are used to test for true or false conditions
FOR loops are used to count how many times something has happened.


Example - WHILE loop
Prompt the player to start the game
IF the player starts the game THEN

WHILE the game is not over
continue playing the game
END WHILE

Display "Game Over"
END IF

Example - FOR loop
FOR the count of numbers 1 to 10
Display the current number
Get the next number
END FOR

Variables

All computer programs require variables to store temporary data or data that may change. The score in a game is a variable as it is always changing. Variables may contain letters, numbers or entire sentences. You can always recognise a variable in a program by the = sign. The word or letter on the left of the = sign is the variable name, whatever is to the right of the = sign is the value to be stored in the variable. When letters, words or sentences are to be stored in a variable, they must be enclosed in quotation marks. Variable names MUST NOT contain a space or they won't work.

Example:
score = 0
playerName = "Player one"
score = score + 1

Functions

Can either be built into the programming language to perform particular (common) tasks or be written by the programmer to perform a task when required. A function can either do something, return a value or accept some input - process it then return a value. A function can be readily identified because it will always have () at the end of it's name.

Example: - Built in flash functions
Math.random() - this function will return a random number between 0 and 1 (How many are there?)
Math.round(5.678) - this function will convert the decimal number to the nearest whole number
gotoAndPlay("StartGame") - this function will tell the flash movie to go to and begin playing from a frame labelled StartGame

Summary

  • All computer programs are constructed using the basic building blocks of sequence, selection and loop.
  • Most, if not all computer programs will use variables to store information or values.
    A variable name MUST NOT contain a space.
  • All computer programs contain functions to perform tasks.
    Functions may be built in to the programming language or be written by the programmer.

Once the learner grasps or understands these programming concepts they are ready to begin the tutorials.

Top of page

 

 

Last Updated on Thursday, 08 April 2010 10:33
 
Copyright © 2012 geoffhill.com.au. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.