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

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

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,
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
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,
, an instance of the custom Picture class (available in the following exercise),
picture01
invokes the
showInfo()
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.
method:
About working with custom classes in an application
is a property of all arrays
length
Chapter 6, "Functions and
245

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