Home > Flex 3 > Create a basic function in Flex 3 using Actionscript 3.0

Create a basic function in Flex 3 using Actionscript 3.0

December 19th, 2008

An explaination of a function and how it works in Actionscript 3.0.

The Basics

private function myFunctionName():void
{
//my code here
}

private – makes the function only available to the current document.
public – make the function available throughout the application.
void – the function will return no data.

myFunctionName – the name of the function. When you need to call the function, this will be the name you will call.

Example: myFunctionName();


The Intermediate

private function myFunctionName(myObj:Object):void
{
//my code here
}

In the above, we have added a required parameter variable of “myObj” which is an object. This means the function requires data for the incoming call to this function. This data so happens to be an object.

Now to call this function, you must use the input parameters.

Example: myFunctionName(myDataObj)

MyDataObj is the object we are sending to the function.


The Advanced

private function myFunctionName(myObj:Object):String
{
var mystr:String = "Kilroy wuz here";
 
return mystr;
}

Now, we changed the ‘void’ to a ‘String’. This tells the function that I want data to leave out of this function. The type is a ‘String’. So I add a return keyword at the end of the function along with the string variable called mystr.

So lets review, This function now takes in an object, and returns a simple string;

Flex 3 ,

  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.