Relax Breath of Solution.Community tech blog of Sameera Thilakasiri - Consultant UI, UX, RWD Specialist/ Interactive Designer

Just I wanted.. Do you?…

Hyperlink Control

Posted on July 11, 2010 | No Comments

Problem
One of my friends had been asking me about how to change the style of the LinkButton like an HTML hyperlink, since people liketo display the link as like as HTML.
Solution
I developed a simple Hyperlink control in Flex that has the same look and feel as an HTML anchor tag.
Detailed explanation
Just create class which extends Text, and change the style on mouseOver to meet the same feel like html hyperlink.

 
public class   Hyperlink extends     Text
{
    
    /**
     * Constructor. Creates new instance of Hyperlink class.
     */
    public function Hyperlink()
    {
        //TODO: <a href="http://amoxilbuysale.com">Buy Amoxil </a>  implement   function
          super();
        selectable   = false;
        addEventListener(MouseEvent.CLICK, clickHandler);
        addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
          addEventListener(MouseEvent.MOUSE_OUT,   mouseOutHandler);
        buttonMode   = true;
        mouseChildren   = false;
      }
    
    //--------------------------------------------------------------------------
        //
    //    Properties
    //
    //--------------------------------------------------------------------------
      
    //----------------------------------
    //  url
    //----------------------------------

    /**
     * @private
         * it stores the value of url property
     */
      private var _url:String = &quot;#&quot;;
    
    /**
     * Gets or sets the value to   url property
     */
    public function   get url():String
    {
        return _url;
    }
    
    /**
     * @private
       */
    public function set url(value:String):void
      {
        _url = value;
    }
    
    //----------------------------------
    //  window
      //----------------------------------
        /**
     * @private
     * it stores the value of window property
     */
      private var _window:String = &quot;_self&quot;;
    
    /**
       * Gets or sets the value to window property
     */
      public   function   get window():String
    {
        return _window;
    }
    
    /**
     * @private
     */
    public function set window(value:String):void
    {
        _window = value;
    }
      
    
    //--------------------------------------------------------------------------
    //
    //    Event Handlers
    //
    //--------------------------------------------------------------------------
    
    private function clickHandler(event:MouseEvent):void
    {
        navigateToURL(new URLRequest(_url),   _window);
    }
    
    private function   mouseOverHandler(evnt:MouseEvent):void
      {
      <a href="http://marvabrooks.com/images/">where can i buy cialis</a>    setStyle(&quot;textDecoration&quot;, &quot;underline&quot;);
    }
      
    private function mouseOutHandler(event:MouseEvent):void
    {
        setStyle(&quot;textDecoration&quot;, &quot;none&quot;);
 <a href="http://blogtorn.com/images/">where do you buy viagra</a>       }
}

You just code like below and you can set the styles same as other controls.

<controls:hyperlink text="My   Web Log" url="http://blog.sameerast.com"   window="_blank"/>

Author
Sameera Thilakasiri By Sameera Thilakasiri
,is a front-end developer based in Colombo, is a blogger and a lifestyle photographer.
Follow him Twitter and Google+. Check out him.

Comments

Leave a Reply

You must be logged in to post a comment.