Flashadvisor logo
:: Desktop Shortcut
:: Flash Help
Advices from Experts

 Submit Here! · Link to Us · Newsletter · Tell a Friend ·

      Add Tutorial |

 

Advertise here










 

Google

Search WWW   
FlashAdvisor.com

 Home > Tutorials  > ActionScript

Flash Actionscript Programming Basics

Author: steve happ | Email
Website : www.video-animation.com


Advertisement


Functions



A function is a named unit, in which statements are logically grouped. It usually contains the following parts:


  • Function Name - e.g. function someName( )

  • Argument list - is enclosed within parentheses after the function name. It contains a comma-separated list of 0 or more arguments. Arguments are passed to the variable with the same name as the argument inside the function.

  • Return Type
    - the datatype of what the function can evaluate to.

  • The function Body
    - is enclosed within a pair of braces { } and contains a sequence of statements.


Here is a template. For AS 1.0 :

Function functionName(arg1, arg2, arg3){
// statements go here
return something if not void return type;
}

example1 (AS 1.0). Type this and compile (Control+Enter):

function test1(arg1, arg2){
// arg1 is passed to the variable with the same name
// in the next line I.e. arg1
trace(arg1);
trace(arg2);
}
// call function
test1(3,"Steve");

Notice that to call a function we write the function name and the argument lists in parentheses.
Template to call a function:

functionName(arg1, arg2);

Example 2 with a return value (AS 1.0)

function returnTest(arg1){
var num = arg1 * 10;
return num;
}
// call function
trace(returnTest(5));

ex. 3

// returns the absolute value of number
function abs(number){
return( i < 0 ? -i : i);
}
// call the method
trace(abs(-350.95);

ex 4
// return the smaller of two values.
function min(num1,num2){
return(num1 <= num2 ? num1: num2);
}
trace(min(27,45));



| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 |

Rate This Tutorial :
We hope the information helped you. If you have any questions or comments, please don't hesitate to post them on the Forums section
Submit your Tutorial at Click Here
  

Home | About Us | Contact Us | Feedback | Advertise with us

Best viewed in 800x600 resolution with Internet Explorer.

Site Developed and Hosted by  ethicsolutions.com
All rights reserved with FlashAdvisor

Flash is a registered trademark of Adobe Systems, Inc.

30 users online