Areost
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Latest topics
» GUYS. "DOOD" IS HERE!
[AS3 Chapter 2] Functions EmptyTue Nov 29, 2011 10:27 am by Karma

» Hi guys! Lalala
[AS3 Chapter 2] Functions EmptyMon Nov 28, 2011 9:26 pm by Pukito

» ARGHHHrrhhghghg
[AS3 Chapter 2] Functions EmptySun Nov 27, 2011 1:25 pm by Pukito

» [Flash Game] - I don't even
[AS3 Chapter 2] Functions EmptySat Nov 26, 2011 11:08 pm by Karma

» Hi, nice to meet you.
[AS3 Chapter 2] Functions EmptySat Nov 26, 2011 12:48 am by Pukito

» I think I see ..
[AS3 Chapter 2] Functions EmptySat Nov 26, 2011 12:47 am by Pukito

» Where Karma goes...
[AS3 Chapter 2] Functions EmptyFri Nov 25, 2011 2:14 am by Karma

» Guys
[AS3 Chapter 2] Functions EmptyTue Nov 22, 2011 9:11 pm by Pukito

» Karmini's Pose
[AS3 Chapter 2] Functions EmptyTue Nov 22, 2011 8:31 pm by Karma

» The Order (1)
[AS3 Chapter 2] Functions EmptySat Nov 19, 2011 10:42 pm by Karma

March 2024
SunMonTueWedThuFriSat
     12
3456789
10111213141516
17181920212223
24252627282930
31      

Calendar Calendar


[AS3 Chapter 2] Functions

Go down

[AS3 Chapter 2] Functions Empty [AS3 Chapter 2] Functions

Post by Pukito 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

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.
Pukito
Pukito
Cobbler

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

http://www.areost.com

Back to top Go down

Back to top

- Similar topics

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