EasyManua.ls Logo

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

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...
About working with custom classes in an application 245
Using methods and properties from a class file
In OOP, members (properties or methods) of a class can be instance members or class
members. Instance members are created for each instance of the class; they are defined to the
prototype of the class when they are initialized in the class definition. In contrast, class
members are created once per class. (Class members are also known as static members.)
Properties are attributes that define an object. For example,
length is a property of all arrays
that specifies the number of elements in the array. Methods are functions that you associate
with a class. For more information on functions and methods, see Chapter 6, “Functions and
Methods,” on page 201.
The following example shows you how you would create a method in a class file:
class Sample {
public function myMethod():Void {
trace("myMethod");
}
}
Next you could invoke that method in your document. To invoke an instance method or
access an instance property, you reference an instance of the class. In the following example,
picture01, an instance of the custom Picture class (available in the following exercise),
invokes the
showInfo() method:
var img1:Picture = new Picture("http://www.helpexamples.com/flash/images/
image1.jpg");
// Invoke the showInfo() method.
img1.showInfo();
The next example demonstrates how you can write a custom Picture class to hold various
pieces of information about a photo.

Table of Contents

Related product manuals