DHANA
Adobe Flex & Flash Developer
Email: info[at]dhana[dot]net
Location: Chennai, India
Profile  |  Portfolio   
Flex Application Zoom effect example:
This example shows some of the useful methods of Flex Application.

* Converting the Flex Application as a Bitmap
* Zoom selected area/pixel
* Get HEX color code from the image pixel.

Source Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalScrollPolicy="off"
verticalScrollPolicy="off"
mouseDown="onSelectPixel(event);"
mouseMove="captureBitmap();"
layout="absolute"
backgroundColor="#FFFFFF"
width="675"
height="362">

<mx:Canvas x="4" y="4" width="666" height="354">
           <mx:Image id="img" scaleContent="false" source="pic_rose.png" x="5" y="5" width="656" height="317"/>
           <mx:Label x="10" y="328" text="Zoom Color Picker:"/>
           <mx:Canvas id="colorBox" x="125" y="328" width="17" buttonMode="true"
           click="showCursor();" height="17" borderColor="#000000" borderStyle="solid"/>
           <mx:Text id="colorCode" x="147" y="327" width="94"/>
</mx:Canvas>

<mx:Script>
<![CDATA[
           import mx.core.UIComponent;
           import flash.display.Bitmap;
           import flash.display.BitmapData;
           import mx.managers.CursorManagerPriority;
           import mx.managers.CursorManager;
           import mx.core.Application;
           import flash.geom.Rectangle;
           import flash.geom.Point;           

           [Embed("cursor.png")]
           private var customCursor:Class;
           private var bmd1:BitmapData;
           private var bmd2:BitmapData;
           private var cursorManual:Boolean = false;
           private var targetImage:Image;

           //generating color from selected bitmap pixel
           private function onSelectPixel(evt:MouseEvent):void
           {
                      if(cursorManual)
                      {
                      var color:int = bmd2.getPixel(evt.localX, evt.localY);
                      colorCode.text = "HEX: "+color.toString(16).toUpperCase();
                      colorBox.setStyle("backgroundColor", color);
                      removeCursor();
                      }
           }

          //change mouse point to custom zoom cursor.
           private function showCursor():void
           {
           CursorManager.setCursor(customCursor, CursorManagerPriority.HIGH, -40, -40);
           cursorManual = true;
           targetImage = new Image();
          this.addChild(targetImage);
          //convert mx.core.Application.application as bitmap
          bmd1 = getBitmapData(UIComponent(mx.core.Application.application));
          bmd2 = new BitmapData(9, 9, false, 0x0000CC44);
          captureBitmap();
          }

          //removing custom cursor on selecting bitmap pixel
          private function removeCursor():void
          {
          CursorManager.removeAllCursors();
          cursorManual = false;
          this.removeChild(targetImage);
          }

          //capturing bitmap on mouseMove
          private function captureBitmap() : void
          {
          //capture particular part on mouseMove() from the bitmap
                    if(cursorManual)
                    {
                    var rect:Rectangle = new Rectangle(mouseX-5, mouseY-5, 10, 10);
                    var pt:Point = new Point(0, 0);
                    bmd2.copyPixels(bmd1, rect, pt);
                    var bm2:Bitmap = new Bitmap(bmd2);
                    targetImage.source = bm2;
                    targetImage.scaleX = 9;
                    targetImage.scaleY = 9;
                    targetImage.x = mouseX-40;
                    targetImage.y = mouseY-40;
                    }
          }

          private function getBitmapData(target:UIComponent):BitmapData
          {
          var newBitmapData:BitmapData = new BitmapData(target.width, target.height);
          var matrixData:Matrix = new Matrix();
          newBitmapData.draw(target, matrixData);
          return newBitmapData;
          }
          ]]>
</mx:Script>
</mx:Application>

Posted by Dhana, 06 Oct 2008
Contact Me

Please send me your Suggestions, feedback, or job requirement by using the contact form below, Thank you.

Contact via IM :
Gtalk: dhanamurugan
Skype: dhanamurugan
Yahoo: dhanamurugan
Favorite Links :

* Flex Org
* Adobe Labs
* Adobe Open Source

Friends :
* Shaleen Jain




© 2011-2012 | http://www.dhana.net. All Rights Reserved.
Tags: Freelance CSS HTML Game Advanced Enterprise application development employment freelancer resume assignments with flex RIA Part Time Parttime Remote Website Australia Sydney USA states UK london New York Malaysia Mumbai India Chennai Bangalore Delhi South Africa Web Developer