[AS3 Chapter 2] Functions
Areost :: Special & Secret :: Schooool
Page 1 of 1
[AS3 Chapter 2] Functions
Functions are snippets of code that can be used re-used over and over again in a piece of code.
Declaring a function
To declare a function, we simply use
The keyword function is used for the declaration of a function, followed the a space and the name of the function. Anything within the curly braces is what the function is actually going to do. If there is nothing within the function, then nothing will happen.
An argument is the thing(lack of better words) that is going to be used in the function.
A parameter is the data type that the result of the function is going to be converted to. Since not all functions result in data outputs, the parameter :void can be used.
Using a function
Typically, you would want to use a function after declaring it. You can call a function by writing the function name followed by ();
However, you do not have to add an argument for a function. Say you have a function that does not need a specific argument, or piece of data, to run.
Then to call the function, all you need to type in is:
notice that there is no argument needed.
..and that's it for functions! I might add some more information later, though, because it is a bit lacking. But the forum will update if I do.
Declaring a function
To declare a function, we simply use
- Code:
function functionName(argument):parameter{
//do nothing
}
The keyword function is used for the declaration of a function, followed the a space and the name of the function. Anything within the curly braces is what the function is actually going to do. If there is nothing within the function, then nothing will happen.
An argument is the thing(lack of better words) that is going to be used in the function.
A parameter is the data type that the result of the function is going to be converted to. Since not all functions result in data outputs, the parameter :void can be used.
Using a function
Typically, you would want to use a function after declaring it. You can call a function by writing the function name followed by ();
- Code:
function decNumber(number):void{
number -= 1;
} //declare a function that decrements a number by 1
decNumber(2); //returns a value of 1
However, you do not have to add an argument for a function. Say you have a function that does not need a specific argument, or piece of data, to run.
- Code:
function posMovie():void{
mc.x = 100;
mc.y = 100; // positions movieclip mc at x:100 y:100
}
Then to call the function, all you need to type in is:
- Code:
function posMovie();
notice that there is no argument needed.
..and that's it for functions! I might add some more information later, though, because it is a bit lacking. But the forum will update if I do.
Similar topics
» [AS3 Chapter 5] Loops
» [AS3 Chapter 1] Variables
» [AS3 Chapter 3] Array Basics
» [AS3 Chapter 6] Event Handlers
» [AS3 Chapter 4] Conditional Statements and Operators
» [AS3 Chapter 1] Variables
» [AS3 Chapter 3] Array Basics
» [AS3 Chapter 6] Event Handlers
» [AS3 Chapter 4] Conditional Statements and Operators
Areost :: Special & Secret :: Schooool
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Nov 29, 2011 10:27 am by Karma
» Hi guys! Lalala
Mon Nov 28, 2011 9:26 pm by Pukito
» ARGHHHrrhhghghg
Sun Nov 27, 2011 1:25 pm by Pukito
» [Flash Game] - I don't even
Sat Nov 26, 2011 11:08 pm by Karma
» Hi, nice to meet you.
Sat Nov 26, 2011 12:48 am by Pukito
» I think I see ..
Sat Nov 26, 2011 12:47 am by Pukito
» Where Karma goes...
Fri Nov 25, 2011 2:14 am by Karma
» Guys
Tue Nov 22, 2011 9:11 pm by Pukito
» Karmini's Pose
Tue Nov 22, 2011 8:31 pm by Karma
» The Order (1)
Sat Nov 19, 2011 10:42 pm by Karma