Powered by With Itt

if() return;

I decided to write a quick little post about the advantages of using “return”. Return works in a really cool way (for those of you who don’t know).

Traditionally you use it like this:

// whatever comes after the colon determines which type to return (String, Number, CustomObject, ect.)
function returnAValue(foo):String
{
// in this case foo will be a String
return foo;
}

//outputs testing
trace(returnAValue(“testing”));

If you’ve never used return - it’s a really nice way to do calculations.

function add(num1:int, num2:int):int
{
var finalNum:int = num1+num2;
return finalNum;
}

var newNumber = add(5, 8);
trace(newNumber); //outputs 13
 

Basically - it runs the function - and then gives back the caller of that function a value. It’s built so that at the return - the function stops running and returns the value you tell it to. Another standard way of using return is to use it as a way to stop a function from running. This is a really streamlined way of using a conditional.

Posted at 12pm on 01/03/08 | no comments | filed under: AS3 READ ON

Replacing Strings in AS3

Although this may be pretty basic - when it comes to dealing with strings, one of the most valuable methods is no doubt the split().join().

So let’s first go over split().

This is from adobe’s live docs:

split(delimiter:String, [limit:Number]) : Array

Split has two Parameters:
delimiter:String - A string; the character or string at which my_str splits.

limit:Number [optional] - The number of items to place into the array.

Ok - don’t get confused. Essentially if you have the string:

var myString:String = “% B % C % D % E % F “;;

The first parameter (delimeter) is whatever character(s) you want to use for splitting the other characters up. So:

trace(myString.split(“%”)); // outputs the array , B , C , D , E , F
 

The second parameter basically tells split how many times you want to do it.
trace(myString.split(”%”, 4) // outputs: B , C , D

So a few really cool applications of this are:

1 - using it to parse out data.
2 - using it to replace or remove a string.

Posted at 5pm on 10/08/07 | 5 comments | filed under: AS3 READ ON

I heart actionscript.

I heart actionscript is a site devoted to the education and sharing of all things actionscript.  These tutorials and articles are based on my experiences and problems I have encountered in my struggle to make the leap from designer to stellar coder.  I hope iHeartActionscript finds you well.

del.icio.us Slashdot Digg Facebook Technorati Google Yahoo

I heart categories.