Latest topics
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

March 2018

Calendar Calendar

[AS3 Chapter 2] Functions

Go down

[AS3 Chapter 2] Functions

Post by Pukito on Sat Oct 08, 2011 11:03 pm

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


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 ();


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.


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:


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.

Put on your sunglasses... Cool and put on your 'fro... afro . Because I'm here now clown.

My friends list:

Rainy albino
Karma scratch
Serene pig

Posts : 377
Monies : 2601
Reputation : 4
Join date : 2011-09-27
Location : MHMM.

View user profile

Back to top Go down

Back to top

Permissions in this forum:
You cannot reply to topics in this forum