ActionScript coding conventions
755
One of the easiest ways to initialize code by using ActionScript 2.0 is to use classes. You can
encapsulate all your initialization for an instance within the class’s constructor function, or
abstract it into a separate method, which you would explicitly call after the variable is created,
as the following code shows:
class Product {
function Product() {
var prodXml:XML = new XML();
prodXml.ignoreWhite = true;
prodXml.onLoad = function(success:Boolean) {
if (success) {
trace("loaded");
} else {
trace("error loading XML");
}
};
prodXml.load("products.xml");
}
}
The following code could be the first function call in the application, and the only one you
make for initialization. Frame 1 of a FLA file that is loading XML might use code that is
similar to the following ActionScript:
if (init == undefined) {
var prodXml:XML = new XML();
prodXml.ignoreWhite = true;
prodXml.onLoad = function(success:Boolean) {
if (success) {
trace("loaded");
} else {
trace("error loading XML");
}
};
prodXml.load("products.xml");
init = true;
}
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...