![MACROMEDIA FLASH MX 2004-LEARNING FLASH Скачать руководство пользователя страница 117](http://html1.mh-extra.com/html/macromedia/flash-mx-2004-learning-flash/flash-mx-2004-learning-flash_manual_3379009117.webp)
Creating a custom class
117
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.
1.
Create an ActionScript file by doing one of the following:
■
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.)
2.
Create a constructor for a Product class by creating a function called Product that takes the
arguments
id
,
prodName
, and
description
:
function Product (id:Number, prodName:String, description:String)
{}
3.
In the constructor function, set the properties of the Product class equal to the setter methods
that you will create:
setID(id);
setProdName(prodName);
setDescription(description);
4.
Wrap the constructor function around the
class
keyword. Be sure to declare each variable used
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);
}
}
5.
Define getter and setter methods for each property of the class, as in the following example. Be
sure to specify
Void
as the return type for the setter methods, and indicate the data type returned
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);
Содержание FLASH MX 2004-LEARNING FLASH
Страница 1: ...Learning Flash...
Страница 8: ...8 Contents...
Страница 34: ...34 Chapter 3 Write Scripts with ActionScript...
Страница 54: ...54 Chapter 6 Create a User Interface with Layout Tools...
Страница 62: ...62 Chapter 7 Draw in Flash...
Страница 68: ...68 Chapter 8 Create Symbols and Instances...
Страница 76: ...76 Chapter 9 Add Animation and Navigation to Buttons...
Страница 104: ...104 Chapter 13 Add Interactivity with ActionScript...
Страница 112: ...112 Chapter 14 Create a Form with Conditional Logic and Send Data...
Страница 122: ...122 Chapter 15 Work with Objects and Classes Using ActionScript 2 0...