ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Dynamic Selection of Concrete Components and Decorations: A Hybrid Car Dealership | 171

16 internal var carDeal:Auto;
17 public var dealText:TextField=new TextField( );
18
19 //Constructor Function
20 public function Deal ( ):void
21 {
22 getRadios ( );
23 getChecks ( );
24 doDealButton ( );
25 showDeal ( );
26 }
27 //Add button from Library
28 private function doDealButton ( ):void
29 {
30 var doDeal:Button=new Button( );
31 this.addChild (doDeal);
32 doDeal.x=215;
33 doDeal.y=195;
34 doDeal.label="Make Deal";
35 doDeal.addEventListener (MouseEvent.CLICK,getPackage);
36 }
37 //**
38 //Get information from Decorator and display it
39 //**
40 private function getPackage (e:MouseEvent):void
41 {
42 getCar ( );
43 getOptions ( );
44 if (carDeal == null)
45 {
46 return;
47 }
48 else
49 {
50 var nowDrive:String=carDeal.getInformation()+"\nTotal=$"+carDeal.price();
51 }
52 dealText.text=formatMachine(nowDrive);
53 }
54 //Format Output
55 private function formatMachine (format:String):String
56 {
57 if (format.indexOf("~") != -1)
58 {
59 format=format.split("~").join("\n");
60 }
61 return format;
62 }
63 //Text Field & Format
64 private function showDeal ( ):void
65 {
66 dealText.width=150;
67 dealText.height=100;

Example 4-48. Deal.as

Free download pdf