EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 755

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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 classs 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;
}

Table of Contents

Related product manuals