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

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

To understand scope and external class files:
1.
Select File > New and then select ActionScript File, and then click OK.
2.
Type or paste the following code into the Script window:
/**
Product class
Product.as
*/
class Product {
private var productsXml:XML;
// constructor
// targetXmlStr - string, contains the path to an XML file
function Product(targetXmlStr:String) {
/* Create a local reference to the current class.
Even if you are within the XML's onLoad event handler, you
can reference the current class instead of only the XML packet.
*/
var thisObj:Product = this;
// Create a local variable, which is used to load the XML file.
var prodXml:XML = new XML();
prodXml.ignoreWhite = true;
prodXml.onLoad = function(success:Boolean) {
if (success) {
/* If the XML successfully loads and parses,
set the class's productsXml variable to the parsed
XML document and call the init function.
*/
thisObj.productsXml = this;
thisObj.init();
} else {
/* There was an error loading the XML file. */
trace("error loading XML");
}
};
// Begin loading the XML document.
prodXml.load(targetXmlStr);
}
public function init():Void {
// Display the XML packet.
trace(this.productsXml);
}
}
Because you are trying to reference the private member variable within an
the
keyword actually refers to the
this
you might expect. For this reason, you must create a pointer to the local class file so that
you can directly reference the class from the
with a Flash document.
284
Classes
instance and not the Product class, which
prodXml
handler. You can now use this class
onLoad
handler,
onLoad

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