Using Function: The Beginner's Nightmare
(Page 1 of 5 )
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.
How new is the function statement?
Beginners and less experienced users of Flash 6 find many benefits when upgrading the Actionscript in FlashMX and Flash MX 2004. Writing Actionscript code with dozens of newly built-in objects, methods, and properties gives developers the opportunity to build high-end interactivity for both Web-based and standalone Flash applications. Many of the built in functions we’ve already used when first starting experimenting with Actionscript. Even using functions is nothing revolutionary, since we can use their full usability in combination with other Actionscript features. This article will cover the basics of creating your own functions, including some more advanced programming techniques. If you’re just starting out, you will need to take the right attitude to what you are doing and to the tools you have got offered.
Then programming with “best practices” in mind, the programmer should centralize the code and make it as modularized as possible. This means that good programming should rely on reusable segments. Any part of application could reach and execute such segment. This is why functions are the best choice when making reusable parts of code. They can save you lots of writing, copying, and pasting through the code. The best part is that functions can be easily located and maintained in one place while affecting all objects that invokes them, without interacting with other functions and parts of code.
Eventually your script would become more complex and you will face repeated or very similar sets of statements on different parts of the main timeline or inside the movieclip actions. This is the right time to consider placing those parts of code into a function.
Next: Function statement >>
More Flash Articles
More By Aleksandar Horvat