Image Cropping in Flex

January 31, 2011

Even though there are many posts on this particular topic still there are many ???, then i thought may be i can write about it, so lets get started.

Lets do things in steps.

  1. Load Image in to Flex App
  2. Convert it to Bitmap and BitmapData objects.
  3. Crop Image using BitmapData object

1.Load Image in to Flex App

private var imageLoader:Loader = new Loader();

private function fnInit():void
{
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImageComplete);
imageLoader.load(new URLRequest(“assets/flower.png”));
}

2.Convert it to Bitmap and BitmapData objects

private var bitmapImage:Bitmap;
private var bitmapDataImage:BitmapData;

//Event.COMPLETE eventHandler for Loader

private function loadImageComplete(e:Event):void
{
bitmapImage = Bitmap(e.target.loader.content);
bitmapDataImage = Bitmap(bitmapImage).bitmapData.clone();
}

3.Crop Image using BitmapData object
Read the rest of this entry »

Advertisements

Tip on LinkBar control in Flex

December 20, 2010

LinkBar control defines the style name “linkButtonStyleName” to specify styles for link buttons, but does not define a style name for a selected link button.For example if you want to apply a specific style for a selected link button in the row of link buttons, you would think for a while, make some try outs, look in to the code, scratch your head for a while,curse flex and may be finnally give up.The real thing is it isn’t defined.But there is a way.

LinkBar control defines a row of LinkButtons, meaning we can access and apply styles to any of these individual Buttons at run time using setStyle method.

Example: Button(lnkBr.getChildAt(0)).setStyle(“fontWeight”,”normal”);

In the above line lnkBr is id of the LinkBar and getChildAt method gets that particular button and then we can apply style to that button using the setStyle method.

Demo

Code

 


Display ToolTips for Combobox List items in Flex4

July 13, 2010

Few months back i made this post in Flex3, it was buggy and i figured later it may not be possible here with my logic.Then comes the Flex4, did anyone tell you Flex4 is awesome, yes it is.The same requirement where you want to show tooltips on comboBox List items on roolover can be achieved easily in Flex4.You may have to read about the new ItemRenderer Class and its architecture for better understanding the code and you can go figure your own requirement then.

Download code below.

Read the rest of this entry »