Accessibility

ActionScript cookbook beta

Create an untyped function

Problem Summary

You need to create a function that takes an argument and then call it.

Solution Summary

Use the function keyword to create a function that takes a variable.

Explanation

ActionScript 2

function foo(bar)
{
   trace(bar);
}

foo("hello");

ActionScript 3

function foo(bar)
{
   trace(bar);
}

foo("hello");

Note: Unlike in ActionScript 2, in ActionScript 3 if you attempt to call the function without any arguments, you will get an error. For example, he following would throw an error:

function foo(bar)
{
   trace(bar);
}
foo();