Internet Commerce

Partners & Affiliates

Developer Channel


Featured Flash FLA
Gallery Downloads 11401 Flash Movies | 5 New Flash Movies Added
What's New | Top 100

Featured FLA

»  Author: Nick Kouvaris
»  Title: Znax
»  Description: Znax is a board game. Click 4 tiles of the same color and form squares as big as you can. You will erase all the tiles inside the square and collect points. Get maximum score if you make a square with game edges.
»  More by: Nick Kouvaris


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 4941 Flash Sites | 1 New Flash Links
What's New | Top 100 Flash Site

Featured Site

»  Author Agence WOP Digital Agency
»  Title: Electricdrum
»  Description: French WOP Agency, 3D websites, Flash (Papervision, Away 3D), event or institutional projects. The agency operates on all digital projects: consulting, design, graphic design, development, online communication. The WOP agency follows you on the implementation of original, creative and optimized digital projects.


Random Links | Add your own Flash Related Links
Flash Tutorials 1481 Tutorials 7 New Tutorials Added!
What's New | Top100

» How To Make A Simple Animation Using Christmas Clips
» Simple Step by step flash game tutorial Spot the diffrence
» How To Make A Moving Text Slide
» Create Flash Banner With Text Float Effect
» How To Make Zoo Photos Slideshow
» How To Make A Dolphin Photos Slideshow
» How To Make A Fathers Day Slideshow
» How To Make A Transparent Background of Your Flash File
» Create Flash Banner With Text Disco Light Effect Today we will introduce you a Text Disco Light eff
» Unknown Tag: Title10
Random Tutorial | Add Site


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Actionscripting/Basic

Categories Flash Actionscript Programming Basics
Author: Steve Happ | Website: http://www.video-animation.com |

 
Page 5
«prev 1 2 3 4 5

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

Functions in AS 2.0

Functions in AS 2.0 are a little different. AS 2.0 allows the setting of specific datatypes. Here is an example :

Function avgReturn(arg1:Number):Number{
Var num = arg1 * 5;
return num;
}
The template for an AS 2.0 function could be :
Function functionName(arg1:DataType,
 arg2:DataType):ReturnType{
// statements go here
return something ;
}
Void is used to specify that there is no return type. E.g.
function noReturn(arg1:Number,
 arg2:String):Void{
trace(arg2+" is a string and "+arg1+" is a number");
}
// call function
noReturn(5,"Steve");

Arrays

An array is a collection of objects . Individual objects are not named but accessed by its position in the array. Try this!

var theArray = new Array(5,4,8,2,1);
for(var i = 0;i<5;i++){
 trace(theArray[i]);
}
Elements are numbered beginning with "0".
In the above array
theArray[0] = 5
theArray[2] = 8
Length is a property of Array. It tells how many elements are in the array. So , from above,
theArray.length = 5

Classes

(As 2.0 only)
A class is a user-defined datatype, an aggregate of named data elements, and a set of operations to manipulate that data. A class definition consists of two parts:

  1. The class head - composed of the keyword class and a name
  2. the class body - enclosed by braces, contains the member definitions
A class name represents a new data type . e.g.
class Dog{
 // data members
 var name:String;
 var age:Number;
 // class method
 function setAge(age1:Number){
 age = age1;
 }
}
Constructors allow us to create an instance of a class . e.g.
var rusty:Dog = new Dog();
// the dot operator (".")
// allows us to access members and methods of that class.
rusty.setAge(7);
rusty.name = "Rusty";

For more information and tutes , go to my site.

«prev 1 2 3 4 5

» Level Basic

Added: : 2005-08-10
Rating: 8.17 Votes: 12
Hits: 674
» Author
Steve Happ is the founder of Steve's Tutes and has been going hard at it developing Flash for Web and CD-rom.
» Download
Download the files used in this tutorial.
Download (0 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments