Home arrow Flash arrow Page 2 - Using Function: The Beginner's Nightmare
FLASH

Using Function: The Beginner's Nightmare


Going past the basic stages of programming for any language usually involves the idea of modularizing code, especially when dealing with opbject oriented programming languages. ActionScript is no exception, and today we'll be getting started with functions, with a few samples to boot.

Author Info:
By: Aleksandar Horvat
Rating: 4 stars4 stars4 stars4 stars4 stars / 20
October 27, 2004
TABLE OF CONTENTS:
  1. · Using Function: The Beginner's Nightmare
  2. · Function statement
  3. · Do you like functions?
  4. · More on reusability: practical example
  5. · Conclusion

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using Function: The Beginner's Nightmare - Function statement
(Page 2 of 5 )

Since this article is not about every variants of practical using of functions, I will touch only the foundation. What are the functions? Here is a simple introduction. In flash Actionscript function comes in a simple syntax:

function myFirstFunction(param  ,param  2, …,param n){
set_of_statements;
}

Function declarations start with keyword 'function', followed by function name and the set of parameters, if any, to be passed to function. You can also setup a function without required parameters; it could be invoked without them.

We can invoke the function by simply using its name as a statement and providing parameters as necessary.

myFirstFunction(param 1, param 2,..., param n);

The number of parameters is up to you. After executing the function, your program will return to the program line right after the line that invokes the function. Let’s see the practical example:

//**set up the function that will add two numbers:
function sum_number(num1, num2){
result=num1+num2;
trace("The result is " add result);
}

To use that function, we will invoke it like this:

sum_number(2, 6);

The output window will show:

The result is 8

This is just the simple example. Functions can be more complex and can contain all kind of actions, calculations and other creative solutions.

You can easily use functions to organize and modularize your code flow. While building an application, you can use functions to simplify your work by placing function on some central place, for example, the main timeline.

Functions have many different aspects of use. They can easily be nested one within another; they can use them as prototypes to define new methods and properties for the objects etc.


blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials