EasyManua.ls Logo

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

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...
252 Classes
For more information on class members (also called static properties), see “Static methods and
properties” on page 249.
A sample file on your hard disk demonstrates how to create a dynamic menu with XML data
and a custom class file. The sample calls the ActionScript
XmlMenu() constructor and passes it
two parameters: the path to the XML menu file and a reference to the current timeline. The
rest of the functionality resides in a custom class file, XmlMenu.as.
You can find the sample source file, xmlmenu.fla, in the Samples folder on your hard disk.
On Windows, browse to boot drive\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\XML_Menu.
On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/XML_Menu.
Using the Singleton design pattern
A common way to use class members is with the Singleton design pattern. A design pattern
defines a formal approach for structuring your code. Typically, you might structure a design
pattern as a solution for a common programming problem. There are many established design
patterns, such as Singleton. The Singleton design pattern makes sure that a class has only one
instance and provides a way of globally accessing the instance. For detailed information on the
Singleton design pattern, see www.macromedia.com/devnet/mx/coldfusion/articles/
design_patterns.html.
Often you encounter situations when you need exactly one object of a particular type in a
system. For example, in a chess game, there is only one chessboard, and in a country, there is
only one capital city. Even though there is only one object, you should encapsulate the
functionality of this object in a class. However, you might need to manage and access the one
instance of that object. Using a global variable is one way to do this, but global variables are
not desirable for most projects. A better approach is to make the class manage the single
instance of the object itself using class members. The following example shows a typical
Singleton design pattern usage, where the Singleton instance is created only once.

Table of Contents

Related product manuals