MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 760

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

About using functions
Reuse blocks of code whenever possible. One way you can reuse code is by calling a function
multiple times, instead of creating different code each time. Functions can be generic pieces of
code; therefore, you can use the same blocks of code for slightly different purposes in a SWF
file. Reusing code lets you create efficient applications and minimize the ActionScript 2.0
code that you must write, which reduces development time. You can create functions on a
timeline, in a class file, or write ActionScript that resides in a code-based component, and
reuse them in a variety of ways.
If you are using ActionScript 2.0, avoid writing functions on a timeline. When you use
ActionScript 2.0, place functions into class files whenever possible, as the following
example shows:
class Circle {
public function area(radius:Number):Number {
return (Math.PI*Math.pow(radius, 2));
}
public function perimeter(radius:Number):Number {
return (2 * Math.PI * radius);
}
public function diameter(radius:Number):Number {
return (radius * 2);
}
}
Use the following syntax when you create functions:
function myCircle(radius:Number):Number {
//...
}
Avoid using the following syntax, which is difficult to read:
myCircle = function(radius:Number):Number {
//...
}
760
Best Practices and Coding Conventions for ActionScript 2.0

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents