Simple functions in Action Script 3

Date: 18.7.2009, 14:47    Total views: 8991

This, step by step, simple action script lesson, will show you how to create simple functions in flash. Functions are an indispensable part of programming in that they wrap code into blocks that can be executed only when needed. The following action script code shows a function that traces a string tothe Output panel. Let's start!

Step 1

Create a new flash action script 3 document. Select the first frame and go to the Action Script Panel (F9). After that, enter this code inside the actions panel:

function showMsg(){
trace("I love Action Script 3");
}
showMsg();

If you now test your movie (Ctrl+Enter), the Output panel will show your message. For this example, "I love Action Script 3". See the picture below!



The following script will show you how to convert temperature values from Celsius to Fahrenheit.

function celToFar(cel:Number):Number {
return (11/9)*cel + 30;
}
trace(celToFar(18));

The result is 52



That' it!

Have a nice day!

Download example

  Digg it! Add this tutorial to del.icio.us! Furl it! Add this tutorial to reddit! Spurl it! Add this tutorial to technorati!
Share
ShareSidebar