Sunday, August 19, 2007

Functions

Functions in as3 are pretty much the same as they were in as2. Before you had the option of returning a value from the function and defining what was going to be returned. Now you HAVE to tell flash what is going to be returned, even if nothing is going to be.

If you're going to return a number, this is how you do it:
function moveBox():Number{
box1_mc.y -= 100;
box1_mc.rotation += 45;
box1_mc.scaleX = 2;
box1_mc.scaleY = 2;
return box1_mc.y;
}

If you're not going to return anything, this is how you do it

function moveBox():void{
box1_mc.y -= 100;
box1_mc.rotation += 45;
box1_mc.scaleX = 2;
box1_mc.scaleY = 2;
}

No comments: