Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

Actionscript Function with Argument and Return Value

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

In previous ActionScript function tutorial with return value, there is no value send to the function to process. Let's recall the process as shown in the diagram below:

ActionScript function with return value

In this tutorial, a value will send into the function for processing when called. And the argument parameter in the function will act as a variable for what value that has sent into the function. The scenerio is illustrated in the following diagram:

ActionScript function with return value

Flash ActionScript Codes:

// Create a custom function
// The name of function is moveBall
// The function will return a value
// xLoc parameter
// - The data type of this return value is Number
// Actually xLoc act as a variable that has a whatever value send to the function
// i.e. xLoc = 300 in this example

function moveBall (xLoc:Number):Number {
// The codes below will be executed when being called or run

// The x-location of ball_mc will be moved by by an amount (value) sent to the function
// i.e. ball_mc.x += 300;
// The value (x location of the ball_mc) is returned back to the code
// The data type of this returned value is Number

return ball_mc.x += xLoc;


// Run or call the function with the function name (moveBall)
// A value (300 in this example) will send to the function to process
// The function return the value (x location of the ball_mc) back to the code
// Therefore moveball (300) will have the value (x location of the ball_mc)
// after moving to an amount of xLoc
output_txt.text = "The ball had been moved to x-location: " + moveBall(300);

Download Flash Source File:

Flash Source File functions-with-argument-parameter-and-return-value.fla


Multiple values can also be sent into the ActionScript function to process. The theory is same as a single parameter.