Friday, August 7, 2009

Hyperlink Component

So many times I see people ask for Hyperlink kind of component in Flex. Though there is LinkButton available in Flex framework but it does not give the feel of traditional hyperlink as it is in HTML. Therefore I tried tweaking the Label component a bit and I guess it is exactly like traditional hyperlink. Trust me, it was far more easier than the imagination. Check out the code below:

package com.components
{
import flash.events.MouseEvent;

import mx.controls.Label;

public class HyperLink extends Label
{
public function HyperLink()
{
super();
this.setStyle('color','#0000FF');
this.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler);
this.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandler);
}

override protected function commitProperties():void{
super.commitProperties();
this.buttonMode = true;
this.useHandCursor = true;
this.mouseChildren = false;
}

private function mouseOverHandler(e:MouseEvent):void{
setStyle('textDecoration','underline');
}

private function mouseOutHandler(e:MouseEvent):void{
setStyle('textDecoration','normal');
}
}
}

You can use this component directly.

Let me know if you like it. :)

Cheers!

2 comments:

Anonymous said...

This is so Good.Useful to easy learening.Thanks provide this opportunity.

sweta said...

technical....
didnt read the blog, it would have been greek to me, still impressed :)