10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

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.

equested location in aList (list indexstarts at 1). This method checks to see if the<br />

delete location is within array bounds, and returns a Boolean value accordingly. Note<br />

the use of the qualifier super to set the text in the update( ) method (line 47). This<br />

allows the method to access the superclass property, listText, directly. This is necessary<br />

as the setter method for the text property is overridden (lines 50–53). In fact,<br />

several public methods in the TextField class that allow direct setting of field contents<br />

are overridden to prevent clients from breaking IListDisplay functionality. The<br />

overridden methods are: setter methods to the text and htmlText properties including<br />

appendText( ), replaceSelectedText( ), and replaceText( ).<br />

The Client<br />

Clients would use the ListDisplayField adapter class just as they would a TextField<br />

class. This is the big advantage to implementing class adapters in <strong>ActionScript</strong> <strong>3.0</strong>, as<br />

the public methods and properties of the existing class behave as expected (unless<br />

overridden). The following client, Main.as shown in Example 5-15, uses a TextFormat<br />

object to set the font and font size of the display object. In addition, the border property<br />

of the text field is set to show the field boundary.<br />

Example 5-15. Main.as (document class)<br />

package<br />

{<br />

import flash.display.MovieClip;<br />

import flash.text.*;<br />

public class Main extends MovieClip<br />

{<br />

public function Main( )<br />

{<br />

// create ListDisplayField<br />

var shoppingListField:ListDisplayField = new ListDisplayField( );<br />

// develop field formatting<br />

var format:TextFormat = new TextFormat( );<br />

format.size = 18;<br />

format.font = "Arial";<br />

// set field location and format<br />

shoppingListField.x = 20;<br />

shoppingListField.y = 20;<br />

shoppingListField.border = true;<br />

shoppingListField.defaultTextFormat = format;<br />

// create list<br />

shoppingListField.addItem("Bread");<br />

shoppingListField.addItem("Butter");<br />

shoppingListField.addItem("Broccoli");<br />

shoppingListField.addItem("Cheese");<br />

// changed mind about Broccoli<br />

198 | Chapter 5: Adapter Pattern

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

Saved successfully!

Ooh no, something went wrong!