MACROMEDIA FLASH 8-FLASH Dokumentacja Strona 259

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 290
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 258
Create a custom class 259
Create a custom class
Although ActionScript includes many classes of objects, such as the
MovieClip class and the Color class, there will be times when you need to
construct your own classes so you can create objects based on a particular
set of properties or methods.
To create a class that defines each of the new objects, you create a
constructor for a custom object class and then create new object instances
based on that new class, as in the following example:
function Product (id:Number, prodName:String, price:Number)
{
this.id = id;
this.prodName = prodName;
this.price = price;
}
To properly define a class in ActionScript 2.0, you must surround all classes
by the
class keyword, and you must declare all variables in the
constructor outside of the constructor.
class Product
{
// variable declarations
var id:Number
var prodName:String
var price:Number
// constructor
function Product (id:Number, prodName:String,
price:Number){
this.id = id;
this.prodName = prodName;
this.price = price;
}
}
NOTE
The following ActionScript is an example only. Do not enter the script in
your lesson FLA file.
NOTE
The following ActionScript is an example only. Do not enter the script in
your lesson FLA file.
Przeglądanie stron 258
1 2 ... 254 255 256 257 258 259 260 261 262 263 264 ... 289 290

Komentarze do niniejszej Instrukcji

Brak uwag