Understanding the ActionScript Language > Creating functions > Returning values from a function |
![]() ![]() ![]() |
Returning values from a function
Use the return
action to return values from functions. The return
action stops the function and replaces it with the value of the return
action. If Flash doesn't encounter a return
action before the end of a function, an empty string is returned. For example, the following function returns the square of the parameter x
:
function sqr(x) { return x * x; }
Some functions perform a series of tasks without returning a value. For example, the following function initializes a series of global variables:
function initialize() { boat_x = _root.boat._x; boat_y = _root.boat._y; car_x = _root.car._x; car_y = _root.car._y; }
![]() ![]() ![]() |