<< Chapter < Page Chapter >> Page >

No lossy compression allowed

Note that this program uses an image from a png file for demonstration purposes.

Unlike a jpg file, (which uses lossy compression) the colors that you extract from a png file are exactly the colors that were stored in the pngfile. That is a requirement for a chroma key process that is based on an exact color match.

An unusual requirement

There is an unusual requirement shown in Listing 2 that you haven't seen in the earlier lessons in this series.

This is the first lesson that I have written explaining a program that loaded and embedded an image file where the program was developed using FlashDevelop (see Publication Issues below).

File organization

In this case, the image file was placed in the same folder as the MXML file. Note that it was necessary for me to precede the name of the image file inListing 2 with a slash character. I have not previously encountered that requirement when using Flex Builder 3. (Note however that inclusion of the slash character in a Flex Builder 3 project doesn't seem to cause a problem.)

Register a CREATION_COMPLETE listener

Finally, Listing 2 registers an event handler to handle CREATION_COMPLETE events fired by the Canvas object.

You learned how and why to use a CREATION_COMPLETE listener in the earlier lesson titled Encapsulation - The Big Picture.

The CREATION_COMPLETE event handler

The CREATION_COMPLETE event handler is shown in its entirety in Listing 3. This method is executed when the Canvas object has been fully created.

The creation_complete event handler.

private function completeHandler( event:mx.events.FlexEvent):void{//Get and save a reference to a Bitmap object // containing the contents of the origImage file.var origBitMap:Bitmap = Bitmap(origImage.content);//Set the width and height of the Canvas object // based on the size of the origBitMap bitmap. Make// ten pixels wider and twice as high as the // bitmap.this.width = origBitMap.width + 10; this.height = 2*origBitMap.height;//Add the original image to the Canvas object at // the default location of 0,0.this.addChild(origImage);//Clone the origBitMap to create a // duplicate.var dupBitMap:Bitmap = new Bitmap( origBitMap.bitmapData.clone());//Put the dupBitMap in a new Image object and// place it on the canvas below the original image. dupBitMap.x = 0;dupBitMap.y = origBitMap.height;var newImage:Image = new Image(); newImage.addChild(dupBitMap);this.addChild(newImage);//Set the alpha value for all pixels in the new // image with a color of pure magenta to zero.processChromaKey(dupBitMap); } //end completeHandler

The call to the method named processChromaKey

With the exception of the call to the method named processChromaKey at the end of Listing 3, I explained everything in Listing 3 in the earlier lesson titled Fundamentals of Image Pixel Processing. I won't waste your time by repeating that explanation here.

Beginning of the processChromaKey method

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with actionscript. OpenStax CNX. Jun 04, 2010 Download for free at http://cnx.org/content/col11202/1.19
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?

Ask