MACROMEDIA FLASH MX 2004-LEARNING FLASH Manual page 117

Learning flash
Table of Contents

Advertisement

Build a custom class
You'll now build a new Product class with getter and setter methods and create an object from the
Product class.
Create an ActionScript file by doing one of the following:
1.
If you're using Flash MX 2004 Professional, select File > New > ActionScript File (Not Flash
Document). Save the document with the name Product.
If you're using Flash MX 2004, open a text editor, such as Notepad. Save the file
with the name Product.as. (Remember to give the file the AS extension, to create an
ActionScript file.)
Create a constructor for a Product class by creating a function called Product that takes the
2.
arguments
id
function Product (id:Number, prodName:String, description:String)
{}
In the constructor function, set the properties of the Product class equal to the setter methods
3.
that you will create:
setID(id);
setProdName(prodName);
setDescription(description);
Wrap the constructor function around the
4.
in the class:
class Product
{
var id:Number;
var prodName:String;
var description:String
function Product (id:Number, prodName:String, description:String)
{
setID(id);
setProdName(prodName);
setDescription(description);
}
}
Define getter and setter methods for each property of the class, as in the following example. Be
5.
sure to specify
for the getter methods.
class Product
{
var id:Number;
var prodName:String;
var description:String
function Product (id:Number, prodName:String, description:String) {
setID(id);
setProdName(prodName);
setDescription(description);
,
, and
prodName
description
as the return type for the setter methods, and indicate the data type returned
Void
:
keyword. Be sure to declare each variable used
class
Creating a custom class
117

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-LEARNING FLASH and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash mx 2004 - actionscript

Table of Contents