Sunday, January 15, 2012

Flash AS3 + PHP: Publishing your flash contents into a PDF file

With the release of Flash Player 10, you can easily create an image file to display all the contents into an image on the fly. But with the help of 'Alive PDF' and Php, you can actually create PDF on the fly.

The following would be a simple demo that I have created. The generated PDF will display 2 blocks of text. The first text would be a capture of the text view in the Flex Application and the second text was inserted into the PDF using the functions provided in the 'Alive PDF' API.

So let us take a look at some coding. :D
<?php

$method = $_GET['method'];
$name = $_GET['name'];

if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
 
 // get bytearray
 $pdf = $GLOBALS["HTTP_RAW_POST_DATA"];
 
 // add headers for download dialog-box
 header('Content-Type: application/pdf');
 header('Content-Length: '.strlen($pdf));
 header('Content-disposition:'.$method.'; filename="'.$name.'"');
 echo $pdf;
 
}  else echo 'An error occured.';

?>
The above Php script was taken from the Alive PDF website.

The following would be the source file of my Main Application in Flex.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
    creationComplete="creationCompleteHandler(event)"
    width="100%" height="100%">
 <mx:Script>
  <![CDATA[
   import mx.events.FlexEvent;
   
   import org.alivepdf.colors.RGBColor;
   import org.alivepdf.display.Display;
   import org.alivepdf.fonts.CodePage;
   import org.alivepdf.fonts.EmbeddedFont;
   import org.alivepdf.layout.Layout;
   import org.alivepdf.layout.Mode;
   import org.alivepdf.layout.Orientation;
   import org.alivepdf.layout.Position;
   import org.alivepdf.layout.Resize;
   import org.alivepdf.layout.Size;
   import org.alivepdf.layout.Unit;
   import org.alivepdf.pages.Page;
   import org.alivepdf.pdf.PDF;
   import org.alivepdf.saving.Method;
   
   //Some Dummy Text
   [Bindable]
   private var msg:String = "Lorem ipsum dolor sit amet, " +
    "consectetur adipiscing elit. Cras nec eros sit amet " +
    "dui sagittis volutpat pharetra et est. Curabitur " +
    "ultricies suscipit volutpat. Aenean feugiat " +
    "ullamcorper pellentesque. Nulla ut venenatis ligula. " +
    "Nam ornare est a odio condimentum bibendum. Sed " +
    "lorem est, tristique at gravida in, blandit vitae leo. " +
    "Etiam lobortis mi vel magna porta tempus. Suspendisse " +
    "in tortor non magna hendrerit vulputate id quis justo. " +
    "Integer vehicula tortor tortor. Cras consequat, tortor " +
    "in cursus consequat, risus justo vehicula arcu, eu " +
    "consequat dolor leo sed felis. In euismod mollis blandit. " +
    "Vivamus tempus rutrum lorem quis commodo. Suspendisse " +
    "condimentum lorem at risus eleifend porttitor. Nulla " +
    "molestie ipsum nec lacus convallis semper sed ut enim. " +
    "Curabitur arcu justo, imperdiet ac rutrum eget, porta " +
    "eget orci. Nulla aliquet tristique rutrum.";
   
   //Path to the Php file used to generate the pdf file
   private var phpUrl:String = "http://bestkirdape.freeiz.com/php/create.php";
   
   //File Name that I'm giving the pdf file
   private var strFilename:String = "PrintOut_Of_PlayingWithAlivePDF.pdf";
   
   //Specify the Embedded font used by the label, lblText
   [Embed( source="fonts/jokerman.TTF", mimeType="application/x-font", fontName="jokermanFont")]
   public var jokermanFont:Class;
   
   //Specify the Embedded font that I'm using in the print out
   [Embed( source="fonts/jokerman.TTF", mimeType="application/octet-stream")]
   public var jokerman_ttf:Class;
   [Embed( source="fonts/jokerman.afm", mimeType="application/octet-stream" )]
   public var jokerman_afm:Class;
   
   //Specify the Font Color
   private var textColor:uint = 0x000000;
   
   //Open up the pdf upon clicking on the button 'Print Content Now!'.
   protected function btnPrint_clickHandler(event:MouseEvent):void
   {
    printContent();
   }
   
   private function printContent():void
   {
    //This variable is needed to specify the Embedded font that
    //we are using
    var font:EmbeddedFont = new EmbeddedFont(
     new jokerman_ttf() as ByteArray
     , new jokerman_afm() as ByteArray
     , CodePage.CP1252
    );
    //Specify the settings of the PDF
    //In my case, I'm using a PORTRAIT view, a size of A4
    //and everything will be calculated in POINT.
    var myPDF:PDF = new PDF(Orientation.PORTRAIT, 
     Unit.POINT, Size.A4);
    //Set the Display Mode of the PDF when it was opened.
    myPDF.setDisplayMode ( Display.FULL_WIDTH );
    //Set the Margins (left, top, right, bottom)
    myPDF.setMargins(10,20,10,20);
    //Add a Page to the PDF
    myPDF.addPage();
    //Change the size of the view,, lblText and ...    
    lblText.width = (myPDF.getCurrentPage().w - 20);
    resizeMe(lblText);
    lblText.validateNow();
    //add it to the PDF
    myPDF.addImage(lblText,null,0,0); 
    //Set the Font of the PDF
    myPDF.setFont(font, lblText.getStyle("fontSize"));
    //Set the Color of the Text of the PDF
    myPDF.textStyle(new RGBColor(Number(textColor)));
    //Change the XY coordinates of the view that
    //I'm going to add
    myPDF.setXY(10, lblText.height + 20 + 10);
    //Create a Cell to display my text and centralised it
    myPDF.addMultiCell(myPDF.getMargins().width,
     lblText.getStyle("fontSize") + 6, msg, 0, "C", 0);
    //*********UPDATED***********
    //Download the PDF file
    //Need to add Download.ATTACHMENT as one of the parameters 
    //in order to download the pdf file.
    myPDF.save( Method.REMOTE, phpUrl, Download.ATTACHMENT, strFilename);
    //Revert the width of the view, lblText.
    lblText.width = 400;
    resizeMe(lblText);
    lblText.validateNow();
   }
   
   protected function creationCompleteHandler(event:FlexEvent):void
   {
    resizeMe(lblText);
   }
   
   //Used to resize the TextArea so that all the text
   //will be shown.
   private function resizeMe(field:TextArea) :void
   {
    field.validateNow();
    field.mx_internal::getTextField().autoSize = 
     TextFieldAutoSize.CENTER;
    field.height = field.mx_internal::getTextField().height;
   }   
   
  ]]>
 </mx:Script>
 <mx:VBox width="100%" verticalAlign="middle" 
    horizontalAlign="center" height="100%">
  <mx:TextArea id="lblText" wordWrap="true"
      backgroundAlpha="0"
      borderThickness="0"
      fontFamily="jokermanFont"
      color="{textColor}"
      text="{msg}" width="400" textAlign="center"/>
  <mx:Button click="btnPrint_clickHandler(event)"
       label="Print Content Now!"/>
 </mx:VBox>
</mx:Application>

* Click here to view the demo of this example.
^ Click here for the source files of this demo.

~ Click here for the website of 'Alive PDF'.
- Click here for the Documentation of the classes of 'Alive PDF'.
** Click here for the .adm file generator.
(Note: you need to upload a .ttf file before you can generate the .adm file.

Monday, January 2, 2012

A stupid font settings of Windows 7

Have you encounter the problem of starting up your Windows 7 and realised that all your Chinese or Korean or Japanese characters have turned into square boxes like the following, []? I have encounter it before and today I am going to share a possible fix for it.

Here are the steps:
  1. Click on the 'Start' button on the bottom left of the screen
  2. Click on 'Control Panel'
  3. Click on 'Appearance and Personalization'
  4. Click on 'Fonts'
  5. In the left pane, click on 'Font settings'
  6. Click on 'Control Panel'
  7. Make sure that the 'Hide fonts based on language settings' check box is not selected
  8. Restart your Laptop or PC and you are done.

* Click here to find out more.

Sunday, January 1, 2012

Flex: Converting your views into ByteArray

Probably they are times where you need to send image captures of the views in the Flex Application to one of your servers but how do you do that? As for this week, I am going to show you how to convert all your views into ByteArray before you convert them into base64 strings and send it to the server.

The following would be the source code for my demo.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
    creationComplete="creationCompleteHandler(event)" 
    width="100%" height="100%">
 <mx:Script>
  <![CDATA[
   import mx.events.FlexEvent;
   //Need to import this class for capturing the view
   import mx.graphics.ImageSnapshot;
   
   //Array to stroe the data for the data grid
   private var arr:Array = new Array();
   private var arr1:Array = new Array();
   
   //Array to store data for the combobox
   private var arr_Content:Array = new Array();
   
   //ByteArray to store the captured image
   private var resultArray:ByteArray;
   
   //Upon clicking on the 'Main' button, 
   //change to the original state
   protected function btnMain_clickHandler(event:MouseEvent):void
   {
    this.currentState = "";
   }
   
   //Upon clicking on the 'Result' button, 
   //change to the 'result' view with the result Image
   protected function btnResult_clickHandler(event:MouseEvent):void
   {
    this.currentState = "result";
   }
   
   //Upon clicking on the 'Capture Now!' button, 
   //Capture the current look and feel of the selected item
   //in the combo box
   protected function btnCapture_clickHandler(event:MouseEvent):void
   {
    updateResult();
    this.currentState = "result";
   }
   
   //Function that create the ByteArray based on the selected item
   //in the combobox
   private function updateResult():void
   {
    resultArray = null;
    var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(
     cmbViewName.selectedItem.data);
    resultArray = imageSnap.data as ByteArray;
   }
   
   //Upon creationComplete, let us populate the views with data
   protected function creationCompleteHandler(event:FlexEvent):void
   {
    var tempObj:Object;
    for(var i:int = 0; i < 8; i ++)
    {
     tempObj = new Object();
     for(var j:int = 0; j < 3; j ++)
     {
      tempObj["col" + (j+1)] = "Row " + (i + 1) 
       + " Col " + (j + 1); 
     }
     arr.push(tempObj);
    }
    dataGrid.dataProvider = arr;
    
    for(var i = 0; i < 20; i ++)
    {
     tempObj = new Object();
     for(var j = 0; j < 5; j ++)
     {
      tempObj["col" + (j+1)] = "Row " + (i + 1) 
       + " Col " + (j + 1); 
     }
     arr1.push(tempObj);
    }
    dataGrid1.dataProvider = arr1;
    
    this.validateNow();
    tempObj = new Object();
    tempObj.label = "Main Application";
    tempObj.data = viewAll;
    arr_Content.push(tempObj);
    tempObj = new Object();
    tempObj.label = "Top Panel";
    tempObj.data = viewBtnsPanel;
    arr_Content.push(tempObj);
    tempObj = new Object();
    tempObj.label = "Contents";
    tempObj.data = viewContent;
    arr_Content.push(tempObj);
    tempObj = new Object();
    tempObj.label = "1st Data Grid";
    tempObj.data = dataGrid;
    arr_Content.push(tempObj);
    tempObj = new Object();
    tempObj.label = "2nd Data Grid";
    tempObj.data = dataGrid1;
    arr_Content.push(tempObj);
    
    cmbViewName.dataProvider = arr_Content;
    this.validateNow();
    updateResult();
   }
   
   //Upon moving into the 'result' state, update the source 
   //of the image
   protected function state1_enterStateHandler(event:FlexEvent):void
   {
    // TODO Auto-generated method stub
    imgResult.source = resultArray;
   }
   
  ]]>
 </mx:Script> 
 <mx:states>
  <mx:State name="result" enterState="state1_enterStateHandler(event)">
   <mx:RemoveChild target="{cmbViewName}"/>
   <mx:RemoveChild target="{btnCapture}"/>
   <mx:RemoveChild target="{dataGrid}"/>
   <mx:RemoveChild target="{dataGrid1}"/>
   <mx:AddChild position="lastChild" relativeTo="{viewContent}">
    <mx:Image id="imgResult" width="100%" height="100%"
        scaleContent="false"/>
   </mx:AddChild>
  </mx:State>
 </mx:states>
 <mx:VBox width="100%" height="100%" verticalGap="10"
    left="10" right="10" top="10" bottom="10"
    id="viewAll">
  <mx:HBox width="100%" id="viewBtnsPanel">
   <mx:Button id="btnMain" label="Main" 
        click="btnMain_clickHandler(event)"/>
   <mx:Button id="btnResult" label="Result" 
        click="btnResult_clickHandler(event)"/>
   <mx:Spacer width="100%"/>
   <mx:ComboBox id="cmbViewName"/>
   <mx:Button id="btnCapture" label="Capture Now!" 
        click="btnCapture_clickHandler(event)"/>
  </mx:HBox>
  <mx:VBox id="viewContent" width="100%" height="100%" 
     verticalGap="10">
   <mx:DataGrid id="dataGrid" width="100%"/>
   <mx:DataGrid id="dataGrid1" width="100%" height="100%"/>
  </mx:VBox>
 </mx:VBox>
</mx:Application>

* Click here to view the demo of this example.
^ Click here for the source files of this demo.

Saturday, December 24, 2011

Flex: Changing the color of the background color of your Pop Ups

I have encountered situations when there's a need to have more than 1 type of background color in your Flex Application. Some Popups might need a black background with 50% opacity some might requires a background with 0% opacity, etc. One of the easiest way to change the background color of the popup will be the step of changing the global styles, but as your Flex Application gets more and more complex, manipulating with the global styles wouldn't be a recommended way of doing things. Hence, I'm going to show you another way of manipulating the background color of your popup today.

The following would be the source code of my main Application.


 
 
  global{
   modalTransparency:0;
   modalTransparencyBlur:0;
   modalTransparencyColor:0;
   modalTransparencyDuration:100;
  }
 
 
 


View that contains some buttons


 
 
  
 
 
 
 


Here comes the important part.
This would be my class that acts like a Pop Up background.
package com.popup
{
 import mx.containers.Canvas;
 import mx.core.Application;
 
 //This class acts as the background in the PopUpManager CLass
 public class PopUpBackground extends Canvas
 {
  public function PopUpBackground()
  {
   super();
   this.height = Application.application.height;
   this.width = Application.application.width;
   this.validateNow();
  }
 }
}

This would be my main class that will be replacing the use of PopUpManager.
package com.popup
{
 import flash.display.DisplayObject;
 
 import mx.collections.ArrayCollection;
 import mx.core.Application;
 import mx.core.IFlexDisplayObject;
 import mx.managers.PopUpManager;

 public class PopUpOverlay
 {
  /** Only one instance of the PopUpOverlay allowed **/
  private static var instance:PopUpOverlay;
  //This is used to store the various Pop Ups
  private var arrayPopupList:ArrayCollection = new ArrayCollection();
  
  public function PopUpOverlay(singletonEnforcer:SingletonEnforcer)
  {
  }
  
  public static function getInstance():PopUpOverlay
  {
   //Create an instance of PopUpOverlay
   if(instance == null) { 
    instance = new PopUpOverlay(new SingletonEnforcer()); 
   } 
   return instance; 
  }
  
  public function createPopUp(parent:DisplayObject, className:Class
    , modal:Boolean = true, backgroundColor:uint = 0xFFFFFF
    , alpha:Number = 0.5):Object
  {
   //If a parent view is not specified, create the 
   //popup on the main Application
   if(parent == null)
   {
    parent = Application.application as DisplayObject;
   }
   //Create the background of the Pop Up using PopUpBackground first
   var tempDisplayObject:* = PopUpManager.createPopUp(parent,PopUpBackground,modal);
   tempDisplayObject.setStyle("backgroundColor", backgroundColor);
   tempDisplayObject.setStyle("backgroundAlpha", alpha);
   this.arrayPopupList.addItem(tempDisplayObject);
   
   //Next, Create the real Pop Up specified by the className
   tempDisplayObject = PopUpManager.createPopUp(parent,className,modal);
   PopUpManager.centerPopUp(tempDisplayObject);
   this.arrayPopupList.addItem(tempDisplayObject);
   return tempDisplayObject;
  }
  
  public function removePopUp():void
  {
   //Remove the create Pop Up View first
   if(this.arrayPopupList.length > 0)
   {
    var tempDisplayObject:IFlexDisplayObject = this.arrayPopupList.removeItemAt(this.arrayPopupList.length - 1) as IFlexDisplayObject;
    PopUpManager.removePopUp(tempDisplayObject);
   }
   //Followed by the background
   if(this.arrayPopupList.length > 0)
   {
    tempDisplayObject = this.arrayPopupList.removeItemAt(this.arrayPopupList.length - 1) as IFlexDisplayObject;
    PopUpManager.removePopUp(tempDisplayObject);
   }
  }
 } 
}
class SingletonEnforcer{};   

* Click here to view the demo of this example.
^ Click here for the source files of this demo.

Friday, December 16, 2011

Flash: Playing with preloaders

I remember the days where I was trying to work around preloaders and trying to force them to display a numerical status of 0 - 100%. Especially, when you are using a in-house server and it just happens that your server is using the same connection as your laptop your desktop, you will never get to see your preloader running. Especially when there are more and more flash sites out there with interesting interactive preloaders, it would be nice to have a COOL preloader up and running. By the way, here's my solution to tackle around and ensure that you will be getting a preloader all the time.

By the way I will be working base on my demos a few weeks ago.

Here's the source file for the preloader.
package com.stretchingDemo
{
 import com.util.preloader.*;
 
 import flash.display.MovieClip;
 import flash.events.Event;
 
 public class Index extends MovieClip
 {
  //To preload your preloader file, which is this file.
  private var tempMainPreloader:MainPreloader;
  //To preload your content file
  private var tempSectionPreloader:SectionPreloader;
  private var _preloader_mc:MovieClip;
  
  //Variable to store your current preloading status 
  private var _preloadNum:Number = 0;
  //Variable to store the highest numerical number to display
  private var _maxPreloadNum:Number = 0;
  
  public function Index():void
  {
   //Start preloading this file
   tempMainPreloader = new MainPreloader(this,5);
   _preloader_mc = this.getChildByName("preloader_mc") as MovieClip;
   this.addEventListener(Event.ENTER_FRAME, progress0Handler);
  }
  
  //function executed when the preloader had finish loading
  private function progress0Handler(event:Event):void
  {   
   var str:String = String((tempMainPreloader.currentProgress)); 
   //Update your text field to display the loading status
   this._preloader_mc.preloader_txt.text = str;
   
   if(tempMainPreloader.currentProgress == tempMainPreloader.maxProgress){ 
    this.removeEventListener(Event.ENTER_FRAME, progress0Handler); 
    loadSubContent(); 
   }
  } 
  
  //function to load the main swf
  public function loadSubContent():void
  {
   //Grab the main swf that you want to load.
   //Usually I will call the prelaoder file 'load_XXX' 
   //where 'XXX' will be the filename of the main swf file. 
   //On top of this, this will help you to structure your 
   //folders properly too. As you can see will my swf files
   //are in the swf folder and my html file is on the root folder.
   var tempStr = String(this.root.loaderInfo.loaderURL).replace(/%5F/gi,"_");
   var tempArray = tempStr.split("load_");
   this.addEventListener(Event.ENTER_FRAME, preloadContentEvent);   
   tempSectionPreloader = new SectionPreloader(tempArray[0] + tempArray[1] ,95);
   tempSectionPreloader.addEventListener(
SectionPreloader.SectionContentLoading, progressHandler2);
  }
  
  //function to update the numerical count on the preloader field
  //And show the main content when the numerical count reaches 100
  private function preloadContentEvent(event:Event):void
  {
   if(_preloadNum < _maxPreloadNum)
   {
    _preloadNum ++;
   }
   this._preloader_mc.preloader_txt.text = Number(_preloadNum + tempMainPreloader.currentProgress);
   if(_preloadNum == _maxPreloadNum && _maxPreloadNum == tempSectionPreloader.maxProgress && tempSectionPreloader.getContent() != null){ 
    tempSectionPreloader.removeEventListener(
SectionPreloader.SectionContentLoading, progressHandler2);
    this.removeEventListener(Event.ENTER_FRAME, preloadContentEvent);  
    this.removeChild(_preloader_mc);
    this.addChild(tempSectionPreloader);
   } 
  }
  
  //function that will be called to update the progress of the loading 
  //of the file when the main file was loading and finish loading
  private function progressHandler2(evt:Event){ 
   _maxPreloadNum = tempSectionPreloader.currentProgress;
  }  
 }
}
* Click here to view the previous example.
^ Click here to view the demo of this example.
~ Click here for the source files of this demo.

Thursday, December 8, 2011

Flash: Disabling default scaling of your flash file

I was browsing through my previous post and I was looking at the demo that I had created. There seems to be something amiss in the example that I had created. After taking a good look at it, I realised that there were white borders appearing on the left and right side of my flash file. and on top of it, the text of the Google Map Component appears to be very blur. I also realise that all of the above were caused by the default property of scaling the flash file. Hence, I have thrown in a fix to it and everything looks much better now. :)

I only make a minor change into the html file and the following would be the source file for the html file.
<html>
 <head>
<style type="text/css">
<!--
html{height:100%}
body {margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px;}
#flashContent {width:100%;height:100%;}
-->
</style>
    
   <!-- Include support librarys first -->  
  <script type="text/javascript" src="jsScript/swfobject.js"></script>
  <script type="text/javascript" src="jsScript/swfforcesize.js"></script>      
  <script type="text/javascript" src="jsScript/swfaddress.js?tracker=null"></script>    


  </head>
  <body>
    <div id="fb-root"></div>
    <table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
    <tr><td align="center">
    <div id="flashContent">
         <h1>You need at least Flash Player 10.0 to view this page.</h1>
                <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
    </div>
  <script type="text/javascript">
   function createSWF(){
    var now=new Date();
    now = Date.UTC(now.getYear(),now.getMonth(),now.getDate(),now.getHours(),now.getMinutes(),now.getSeconds());
    var swfURL = "swf/Main.swf?date=" + now;
    var flashvars = {};
    //Remove default scaling of the flash file
    var params = {scale :"noscale"};
    var attributes = {};
    attributes.name = "flashContent";
    swfobject.embedSWF(swfURL, "flashContent", "100%", "100%", "10.0.2", null, flashvars, params, attributes);    
    swfobject.addLoadEvent(function(){
     var obj = document.getElementById("flashContent");
     if(obj){
      var forcesize = new SWFForceSize(obj, 800, 600);
      forcesize.onLoadDiv();
     }
    })
   }
   createSWF();
  </script>    
     </td></tr></table>  
</body>
</html>
* Click here to view the previous example.
^ Click here to view the demo of this example.
~ Click here for the source files of this demo.

By the way, if you are adding or embedding a Flash file into a webpage or website, I would highly recommend you to use the Javascript classes known as SWFObject to add or embed your Flash file into a webpage or website.

- Click here to find out more about SWFObject.

Wednesday, November 30, 2011

Changing the color scheme of the map of Google Maps Component

If you have seen websites like Volkswagen "Think Blue." Road Trip before, you would probably have seen the Google Map that was in Blue color. So how do you actually do that in Flash? That would be my main objective of sharing this post today. :)


The following would be the source codes of my Flash File.
package com.TintGoogleMap
{
 //Import the classes required for Google Maps
 import com.google.maps.LatLng;
 import com.google.maps.Map;
 import com.google.maps.MapEvent;
 import com.google.maps.MapType;
 import com.google.maps.controls.MapTypeControl;
 import com.google.maps.controls.PositionControl;
 import com.google.maps.controls.ZoomControl;
 
 import flash.display.MovieClip;
 import flash.display.Sprite;
 import flash.events.Event;
 import flash.filters.ColorMatrixFilter;
 import flash.geom.Point;
 
 //Import the Component Class for Numeric Stepper
 import fl.controls.NumericStepper;
 
 public class Main extends Sprite
 {
  private var myMap:Map;
  //Set the base width and height of the Flash File
  private var baseWidth:Number = 800;
  private var baseHeight:Number = 600;
  private var _mcMap:MovieClip;
  private var _mcColorControls:MovieClip;
  
  public function Main()
  {
   //execute the function 'addToStageEvent' when the flash file
   //have been added to stage.
   this.addEventListener(Event.ADDED_TO_STAGE, addToStageEvent); 
  }
  
  private function resizeEvent(event:Event):void
  {
   //Move the holder of the Map to the top left corner
   //of the flash file
   _mcMap.x = (stage.stageWidth - baseWidth) / -2;
   _mcMap.y = (stage.stageHeight - baseHeight) / -2;
   
   //Move the controls to the bottom right of the flash file
   _mcColorControls.x = baseWidth + 
    (stage.stageWidth - baseWidth) / 2;
   _mcColorControls.y = baseHeight + 
    (stage.stageHeight - baseHeight) / 2;
   
   //Resize the Google Map Component to fill up the flash file
   myMap.setSize(new Point(stage.stageWidth, stage.stageHeight));
  }
  
  private function addToStageEvent(event:Event):void
  {
   _mcMap = this.getChildByName("mcMap") as MovieClip;
   _mcColorControls = this.getChildByName("mcColorControls") as MovieClip;
   setupStepperControls();
   
   //setup the Google Map Component and add it to the map holder
   myMap = new Map();
   myMap.key = "your_api_key";
   myMap.sensor = "false";
   //execute the function 'onMapReady' when the map is ready 
   //or created success
   myMap.addEventListener(MapEvent.MAP_READY, onMapReady);
   resizeEvent(null);
   _mcMap.addChild(myMap);
   
   //execute the function 'resizeEvent' when the flash file
   //have been resized
   stage.addEventListener(Event.RESIZE, resizeEvent);
   resizeEvent(null);
  }
  
  private function onMapReady(event:Event):void {
   //add the respective Google Map Component controls
   myMap.addControl(new ZoomControl());
   myMap.addControl(new PositionControl());
   myMap.addControl(new MapTypeControl());
   updateColorScheme();
  }  
  
  private function setupStepperControls():void
  {
   var tempSelector:NumericStepper;
   for (var i:int = 0; i < (_mcColorControls.numChildren - 1); i ++)
   {
    tempSelector = _mcColorControls.getChildAt(i) as NumericStepper;
    
    //execute the function 'updateColorScheme' when the 
    //values of the NumericStepper have been changed
    if(tempSelector)
     tempSelector.addEventListener(Event.CHANGE, updateColorScheme);
   }
  }
  
  public function updateColorScheme(event:Event = null):void  
  {  
   var matrix:Array = new Array();
   var colorArray:Array = ["R","G","B","A"];
   var tempSelector:NumericStepper;
   //Create a fake matrix(Array) based on the values of the
   //NumericStepper on the bottom right of the screen
   for(var i:int = 0; i < colorArray.length; i ++)
   {
    for(var j:int = 0; j < 5; j ++)
    {
     tempSelector = _mcColorControls.getChildByName("mc" + 
      colorArray[i] + "" + j) as NumericStepper;
     matrix.push(tempSelector.value);
    }
   }
   
   _mcColorControls.txtOutput.text = "[" + matrix.toString() + "]";
   
   //Create a Color Matrix Filter and apply the filter to the
   //Google Map Component
   var CMF:ColorMatrixFilter = new ColorMatrixFilter(matrix);  
   mapArea.filters = [CMF];  
  }  
  
  //getter function to get the main map which will be used in
  //changing the colors
  public function get mapArea():*  
  {  
   var mapPart:* = myMap.getChildAt(1);  
   return mapPart.getChildAt(0);  
  }  
 }
}
* Click here to view the demo of this example.
^ Click here for the source files of this demo.

** Click here for the website of Volkswagon Singapore "Think Blue" Road Trip.
^^ Click here for the blog of JActionScripters, that have taught me about
   the secret behind this.
-- Click here to learn more about Color Matrix Filter in Flash.
~~ Click here to learn more about the Class ColorMatrixFilter in Flash.