Flash
  Home arrow Flash arrow Page 3 - Using Concrete Decorator Classes
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

Using Concrete Decorator Classes
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-12-24

    Table of Contents:
  • Using Concrete Decorator Classes
  • Deadly sins
  • Implementing the Good and Evil Decorator
  • Charting souls

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using Concrete Decorator Classes - Implementing the Good and Evil Decorator


    (Page 3 of 4 )

    Instead of a single implementation, you can try out two different implementations. The first one dresses up the two different concrete components, and sends the results to the output window. The second takes the results, uses them to place movie clips on a “soul graph,” and adds a label to an angel or devil movie clip—depending on whether good or evil is predominant.

    Dual implementation

    The first implementation decorates both the Dick andJaneconcrete components. This one is set up to use all 14 deadly sins and heavenly virtues, but you can use any combination you want. As each concrete component (lifeandlight) is wrapped, the good and evil properties are incremented or decremented, depending on which decorator wraps the concrete component. The reference to thecomponentsobject in each of the decorators is a reference to the concrete component being wrapped. With each new decorator, then, the value goes up and down depending on the wrapping decorator. Save Example 4-36 asMainDual.asin an ActionScript file. Open a new Flash document file, and save it as aDual.fla. Type in MainDual in the Document class window in the Dual.fla Properties panel, and resave it as MainDual.as. Now test the movie.

    Example 4-36. MainDual.as

    package
    {
       import flash.display.Sprite;
       public class MainDual extends Sprite
       {
         
    public function MainDual()
         
    {
             trace("||--Judging--||");
             var life:Component=new Dick();
             var light:Component=new Jane();
             //***Add Good
             life=new Courage(life);
             light=new Hope(light);
             light=new Compassion(light);
             life=new Openness(life);
             life=new Diligence(life);
             light=new Justice(light);
             //***Add Evil
             light=new Malice(light);
             life=new Prejudice(life);
             life=new Dogmatisms(life);
             life=new Arrogance(life);
             life=new Indifference(life);
             life=new Rage(life);
             light=new Obsfuscation(light);
             trace(life.getSoul()+"\nTotal Virture: "+ 
                 
    (life.good()-life.evil()));
             trace(light.getSoul()+"\nTotal Virture: "+
                 (light.good()-light.evil()));
          }
       }
    }

    The output for all of the good and evil together is:

      ||--Judging--||
      Dick's soul 
      |Courage|Openness|Diligence|Prejudice| Dogmatisms|Arrogance
         
    |Indifference|Rage
      Total Virture: -38
      Jane's soul 
      |Hope|Compassion|Justice|Malice| Obsfuscation
      Total Virture: 10

    Because thetrace()statement subtracts theevil()method from thegood()method total value, any positive results indicate an abundance of good characteristics, and a negative result shows a plethora of negative traits.

    You can “multi-wrap” using the same decorator more than once on the same concrete component. (Someone who thinks he can get the month-behind project done on time by not sleeping for a week is doubly hopeful, has a triple dose of diligence, and perhaps a double dose of arrogance.)

    More Flash Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "ActionScript 3.0 Design Patterns Object...
     

    Buy this book now. This article is excerpted from chapter four of ActionScript 3.0 Design Patterns Object Oriented Programming Techniques, written by William B. Sanders and Chandima Cumaranatunge (O'Reilly, 2007 ISBN: 0596528469). Check it out today at your favorite bookstore. Buy this book now.

    FLASH ARTICLES

    - Critical Flash Vulnerability Heats Up the Web
    - More on Nonpersistent Client-Side Remote Sha...
    - Nonpersistent Client-Side Remote Shared Obje...
    - Using the Decorator Pattern for a Real Web S...
    - Using Concrete Decorator Classes
    - Delving More Deeply into the Decorator Patte...
    - The Decorator Pattern in Action
    - A Simple Decorator Pattern Example
    - Decorator Pattern
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek