ActionScript 3.0 Design Patterns

(Chris Devlin) #1

124 | Chapter 3: Singleton Pattern


open the Convert to Symbol dialog box. TypeCartas the Name, and select
Movie clip as the Type. Click the Export for ActionScript checkbox, and click
OK. (See Figure 3-7 for a visual idea of the cart.)


  1. Double-click the Shopping Cart movie clip on the stage to open it for editing. Use
    the Text tool to add a Dynamic text field. Give it the instance nametotal_txtin
    the Properties panel.

  2. Exit the Symbol Editing Mode by clicking on the Scene 1 icon. Delete the movie
    clip from the stage. (Don’t worry; it’ll still be in the Library panel.)

  3. Test the application by pressing Ctrl + Enter (Command + Return on the Mac.)


When the application runs, it creates a singleShopCartclass instance, and, using the


kaChing( )method, it adds a total of $10.06 to the text field in the shopping cart


movie clip as shown in Figure 3-7.


Figure 3-7. Correct results with two references to a single instance

Free download pdf