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.

Example 5-14. ListDisplayField.as<br />

34 public function clear( ):void<br />

35 {<br />

36 aList = [];<br />

37 this.update( );<br />

38 }<br />

39<br />

40 internal function update( )<br />

41 {<br />

42 var listText:String = "";<br />

43 // split the array to create a string separated by returns<br />

44 for (var i:Number = 0; i < aList.length; i++) {<br />

45 listText += aList[i] + "\r";<br />

46 }<br />

47 super.text = listText;<br />

48 }<br />

49<br />

50 override public function set text(s:String):void<br />

51 {<br />

52 throw new Error("Cannot directly set text property - use<br />

addItem( ) method");<br />

53 }<br />

54<br />

55 override public function set htmlText(s:String):void<br />

56 {<br />

57 throw new Error("Cannot directly set htmlText property");<br />

58 }<br />

59<br />

60 override public function appendText(s:String):void<br />

61 {<br />

62 throw new Error("Cannot append text - use addItem( ) method");<br />

63 }<br />

64<br />

65 override public function replaceSelectedText(s:String):void<br />

66 {<br />

67 throw new Error("Cannot replace selected text");<br />

68 }<br />

69<br />

70 override public function replaceText(beginIndex:int, endIndex:int,<br />

newText:String):void<br />

71 {<br />

72 throw new Error("Cannot replace text");<br />

73 }<br />

74 }<br />

75 }<br />

The ListDisplayField adapter extends the TextField class, and implements the<br />

IListDisplay interface. The constructor calls the super( ) method to invoke the constructor<br />

in the superclass TextField (line 13). The implementation is straightforward<br />

in that the list of items to display is stored in an array called aList that is a property<br />

of the class. The addItem(s:String) method appends the passed string value to the<br />

end of the aList array. The deleteItemAt(i:uint) method deletes the item at the<br />

Example: List Display Adapter | 197

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

Saved successfully!

Ooh no, something went wrong!