A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11336 Flash Movies | 2 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Surjit Dhami
» Title: Book
» Description: Book
» More by Surjit Dhami


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

Featured Site

» Posted in the Flash Kit Links section
» Title: All-American Rejects
» Description: Get to know this great band by exploring their "practice room".


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

» Create xml slideshow with free template
» How to Insert a Multilingual Subtitle Into Your Flash Video Studio
» How to Create Cool Halloween Slideshow
» Debugging flash using the Firebug console
» Create Flash Slideshow on Blogger
» FLASH TRICKS IN WEB ADVERTISING: FLASH BANNERS
» HTML Photo Gallery Tutorial
» Create your first flash site – PART 1
» How to Make a Flash Photo Gallery
» Unknown Tag: Title10
Random Tutorial | Add Site

Trading Customer Accounting (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume


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: 670
» 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
 
   
 

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs