Flash
  Home arrow Flash arrow Page 4 - 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 - Charting souls


    (Page 4 of 4 )

    Like any of the other design patterns, what you do with the output is up to you. However, because ActionScript 3.0 is part of Flash, this next implementation shows how to place the output into different formats with graphic elements. The getSoul() generates a string, and the good() and evil() methods generate numbers. The string will be placed in a text field embedded in a movie clip, and the vertical position of the movie clip will be determined by the values generated by the good() and evil()methods. To get started, save the script in Example 4-37 in an ActionScript file namedSoul.as.

    Example 4-37. Soul.as

    package
    {
       import flash.display.Sprite;
       import flash.display.MovieClip;
       public class Soul extends Sprite
       {
         
    //Instantiate the two MovieClip objects in
          //the Library
          var devil:Devil=new Devil();
          var angel:Angel=new Angel();
          public function Soul()
          {
            
    var life:Component=new Jane();
             //***Add Good***
             life=new Courage(life);
             life=new Compassion(life);
             life=new Hope(life);
             //life=new Integrity(life);
             life=new Openness(life);
             life=new Diligence(life);
             life=new Justice(life);
             //***Add Evil***
             life=new Malice(life);
             life=new Prejudice(life);
             //life=new Dogmatisms(life);
             life=new Arrogance(life);
             //life=new Indifference(life);
             //life=new Rage(life);
             //life=new Obsfuscation(life);
             setAngelDevil(life.good(),life.evil(),life.getSoul());
         
    }
          private function setAngelDevil(right:Number,wrong:Number,
             eternalsoul:String)
         
    {
             this.addChild(devil);
             this.addChild(angel);
             var booWrong:Number=Number(wrong>0);
            
    var booRight:Number=Number(right>0);
             devil.x=330;
             devil.y=270-((wrong*booWrong)*(270/72));
             angel.x=96;
             angel.y=270-((right*booRight)*(270/60));
             if (booWrong)
             {
               
    devil.soul_txt.text=eternalsoul;
             } else
             {
               
    angel.soul_txt.text=eternalsoul;
             }
          }
       }
    }

    In looking at the script, all it does is pass the three different values generated by the getter methods,good(),evil()andgetSoul(), to thesetAngelDevil()function. ThesetAngelDevil()function uses two movie clips from the library and positions them on the stage. Depending on the outcome, the concrete component’s name appears in the angel or devil icon. Figure 4-7 shows what the output will look like. Use it as a guide for setting up your stage.


    Figure 4-7.  Decorator generated values used for placement and labels

    The following steps guide you through the process of preparing the two MovieClip classes in the Flash IDE and setting the stage as a “soul chart.”

    1. Open a new Flash document file, type in Soul in the Document class window, and save the file as SoulChart.fla.
    2. Add a layer to the existing layer, and name the top layer, Labels and the bottom layer “Lines.” (Say that last sentence fast three times!)
    3. Select Insert -> New Symbol from the menu bar. Type Angel in the Name window, and click the Export for ActionScript checkbox. Click OK. You are now in the Symbol Edit Mode. (Be sure to capitalize the “A” in “Angel” because this is a class name.)
    4. In the Symbol Edit window, draw or import an image of an angel.
    5. Click the Text icon in the Tools panel, and select Dynamic Text for the type of text. In the Properties panel, provide the instance namesoul_txtfor the dynamic text object.
    6. Exit the Symbol Edit Mode by clicking the Scene 1 icon. You should now see a movie clip icon in the Library named “Angel.”
    7. Repeat steps 3 to 6, substituting “Devil” for “Angel.” Once you’re finished, you should see both Devil and Angel movie clip icons in the Library panel.
    8. Click the Lines layer and add 11 horizontal lines and one vertical line as shown in Figure4-7. Lock the layer.
    9. Click the Labels layer, number the lines from 0 to 100, and place a “Good” and “Evil” label at the top of the stage as shown in Figure 4-7. Lock the layer and save the file once again.

    By adding and removing the comment lines in theSoul.asfile, you can change the vertical positions of the angel and devil images. You may have to make some adjustments depending on the size of your angel and devil movie clips and/or if you change the default size of the stage from 550 by 400.

    Please check back next week for the conclusion to this article.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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 4 Hosted by Hostway
    Stay green...Green IT