03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Book.prototype.getTitle = function():String {<br />

return "Catcher in the Rye";<br />

};<br />

Book.prototype.addProperty("bookcount", Book.prototype.getQuantity,<br />

Book.prototype.setQuantity);<br />

Book.prototype.addProperty("bookname", Book.prototype.getTitle, null);<br />

var myBook = new Book();<br />

myBook.bookcount = 5;<br />

trace("You ordered "+myBook.bookcount+" copies of "+myBook.bookname);<br />

The following example shows how to use the implicit getter <strong>and</strong> setter functions available in<br />

ActionScript 2.0. Rather than defining the Book function <strong>and</strong> editing Book.prototype, you<br />

define the Book class in an external file named Book.as. The following code must be in a<br />

separate external file named Book.as that contains only this class definition <strong>and</strong> resides within<br />

the Flash application's classpath:<br />

class Book {<br />

var books:Number;<br />

function set bookcount(numBooks:Number):Void {<br />

this.books = numBooks;<br />

}<br />

function get bookcount():Number {<br />

return this.books;<br />

}<br />

function get bookname():String {<br />

return "Catcher in the Rye";<br />

}<br />

}<br />

The following code can then be placed in a FLA file <strong>and</strong> will function the same way as it does<br />

in the previous examples:<br />

var myBook:Book = new Book();<br />

myBook.bookcount = 5;<br />

trace("You ordered "+myBook.bookcount+" copies of "+myBook.bookname);<br />

See also<br />

getProperty function, setInterval function<br />

constructor (Object.constructor property)<br />

public constructor : Object<br />

Reference to the constructor function for a given object instance. The constructor property<br />

is automatically assigned to all objects when they are created using the constructor for the<br />

Object class.<br />

Object 523

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!