Archive for July, 2008

Jul 07 2008

Event Listeners

Published by Andy G. Cook under Beginners, Flash

Event Listeners:

Flash is based around event listeners. The basic idea of an event listener is pretty simple. Flash is constantly waiting for something to happen. As soon as the event happens, Flash runs the function that is connected to the listener.

Many cool things can be done with event listeners. Most user interaction is done though the Event Dispatcher class in Flash. There are tons of events in Flash but some of the most common ones for games are the KeyboardEvent and the MouseEvent.

Basic structure:

The basic structure of an event listener is pretty standard throughout Flash no matter what the event actually is.

Example:

object.addEventListener ( TypeOfEvent.ACTUAL_EVENT, functionToHandleEvent );

Object: This is the object you are putting the event on. It can be a variable, the stage, etc.

TypeOfEvent: The type of event ( Event, KeyboardEvent, MouseEvent, etc)

ACTUAL_EVENT: This is the thing you are actually listening for. I wrote it in all caps because they are always written in all caps.

functionToHandleEvent: This is your function that is going to be run once the event actually happens. It is called the handler function.

Example Handler:

function  functionToHandleEvent ( EVENT:TypeOfEvent ) : ReturnType
{
        Code to be executed
}

Continue Reading »

No responses yet

Jul 06 2008

Variables

Published by Andy G. Cook under Beginners, Flash

What is a variable? It is essentially a representation of a number, string of characters, or anything else that can change values.

Remember math class? Remember how “x” never really was the letter x, instead a number could be stored into x and x could change? Well, that is how variables work in ActionScript.

Continue Reading »

No responses yet

Jul 01 2008

Conditionals

Published by Andy G. Cook under Beginners, Flash

If statement:

Think about life. Oftentimes, you make choices based on something.

If I have $.99, I can buy this doughnut, otherwise, I can’t.

If I get a 90 or above, I get $50. If I get above a 80 but below a 90, I am going out for ice cream, but if I get below an 80, I am grounded.

These types of statements are called conditional statements, and they come up in programming all the time. Most are in the form of an if/else statement. Lets take the aforementioned examples and make them into code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if ( nMoney >= .99 )
{
	bCanGetDoughnut = true;
}
 
if ( nGrade >= 90 )
{
	nMoney += 50;
}
else if ( nGrade >= 80 && nGrade < 90 )
{
	bGettingIceCream = true;
}
else
{
	bGrounded = true;
}

Basic structure:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if ( /*Something happens*/ )
{
	/*Do this code and end the if statement*/
}
else if ( /*the first thing didn’t happen, but this one did*/ )
{
	/*Do this code and end the if statement*/
}
else if ( /*So far nothing is true*/ )
{
	/*Do this code and end the if statement*/
}
else
{
	/*Nothing else was true, so lets just run this code*/
}

Continue Reading »

No responses yet

« Prev