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

May 2019

Calendar Calendar

[AS3 Chapter 2] Functions

Go down

[AS3 Chapter 2] Functions Empty [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 : 3035
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