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

Just I wanted.. Do you?…

TextArea Automatically Resize

Posted on July 11, 2010 by Sameera Thilakasiri

Posting this just on the off-chance someone else ran how do i buy viagra online | buy cialis canadian | cheap levitra generic into the issue and the solutions on the net weren’t up to their needs.

In a project, I’m using a TextArea control because it’s better at displaying images inline using the htmlText property — the Text control completely failed. But once I did this, I kept finding the text getting clipped.

TextArea controls expect that they’ll have a fixed or percentage width and height. Most of the suggestions I’ve seen require the use of getTextMetrics() for the mx_internal textField control of the TextArea. This fails miserably if there is any font sizing or inlined images in the html.

This (placed in creationComplete) works nearly perfectly:

protected     function <a href="http://marvabrooks.com/images/">buy levitra online</a>    onCreationComplete(event:Event):void
{
	//textAreaControl <a   href="http://onlineacompliacheap.com   ">buying   acomplia</a>  is the id of the control   you want to resize to contain it's text.
	textAreaControl.validateNow() ;
	textAreaControl.mx_internal::getTextField().autoSize = TextFieldAutoSize.LEFT ;
	textAreaControl.mx_internal::getTextField().validateNow();
	textAreaControl.height     = textAreaControl.mx_internal::getTextField().height   ;
}

It would be just as easy to subclass the TextArea control and apply this on set htmlText().

One minor error with this is that before creationComplete is run, the text is briefly visible in it’s unsized state. If you’re using this in a subclassing situation, no worries, but if you’re applying this from a parent->child situation, you’re going to have to handle the appearance changes (but that’s fairly obvious — just felt it needed qualifying).

Hope that helps someone out.

Update:

Created the class in the comments below, figured I’d update the article:

package us.aut0poietic.controls.text
{
      import flash.text.TextFieldAutoSize;
    import mx.core.mx_internal;
    import mx.controls.TextArea;

    public class AutoSizeTextArea extends TextArea
    {
        public function AutoSizeTextArea()
        {
            super();
        }
        override public function set text(value:String):void
        {
            super.text = value ;
            updateSize()   ;
        }
          override public function set htmlText(value:String):void
          {
              super.data   = value ;
            updateSize()   ;
          }
          override protected function   commitProperties():void
        {
            super.commitProperties() ;
            updateSize() ;
        }
        protected function updateSize():void
          {
            if(mx_internal::getTextField() != null)
            {
                validateNow() ;
                mx_internal::getTextField().autoSize = TextFieldAutoSize.LEFT ;
                    mx_internal::getTextField().validateNow();
                  this.height = mx_internal::getTextField().height ;
            }
        }
    }
}

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.

Hyperlink Control

Posted on July 11, 2010 by Sameera Thilakasiri

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.

Display HTML content in Flex screen

Posted on July 11, 2010 by Sameera Thilakasiri

Problem
I have a application where i need to display HTML text in flex screen (using TextArea). Problem is HTML text contains
tag which is not supported in flex htmlText property. So all the information under

tag is being displayed in single row. Is there any component which understands

tag and display in a tablur format.

Solution
Use Iframes for Flex.
Detailed explanation
An IFrame is an entity which has the ability to load any external HTML in Flex.You can either go for giving a direct URL as to the soource of the IFrame or you could also give a HTML text which understands things like Table and all.
You can get IFrames for Flex from http://code.google.com/p/flex-iframe/

You can also refer for Table and HTML support in flex.
http://code.google.com/p/flex-htmlfilter/
http://code.google.com/p/flex-table/

By default, Flash only supports a small subset of HTML in htmlText fields Reference:

Anchor tag ()
Bold tag   ()
Break tag ()
Font tag ()
Image tag ()
Italic   tag ()
List item tag ( 
  • ) Paragraph buy viagra online order | buy cialis tadalafil | buy levitra vardenafil 424 buy viagra | where to buy cialis without prescription | order online levitra tag () Text format tag () Underline tag () Flex-htmlFilter can be utilised to extend the HTML support of htmlText fields by enabling the use of: Unordered list tag (
      1. ) Table tag (
    • ) Ordered list tag (
  • ) Table row tag () Table column tag (
    ) Table header column () Table caption tag (
    ) Heading tags (

    ) As well as this, it allows the use of some "custom" buy viagra pill | where can i buy cialis | buy levitra online tags and some custom attributes of the above tags.

    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.

    File download without any server (ASP,PHP,etc) script in flash player 10

    Posted on June 3, 2010 by Sameera Thilakasiri

    While reading through flash player 10 API, i come to know cheap buy Without Prescription online Ampicillin that FileReference Class has updated with few new features. FileReference Objetc now can take file into flash player (upload) and give file back to file system (download) without any server side script like ASP, PHP etc. flash player 10 can perform these tasks without any middle man 🙂

    Below example allows user to sketch something on screen using mouse, after user done with sketching once he clicks on “download your sketch” button, download dialog is get displayed, select a location where you want to save and click on ok. you will get you sketched image as JPEG file. Looks NICE 🙂 . Example uses Bitmap.draw() method to draw the sketch as bitmap and example uses JPEG Encoder to convert bitmap data to JPEG encoded (you can download JPEG encoder at corelib project) after that FileReference.save() method to save the sketch image.

    Note : Example targets the flash cs4 (you buy viagra online order make some modification to the code if you want to run this on flex builder with flex 4 sdk). I am going to post this updated code for flex 4 sdk soon.

    settings:

    1. make sure that you have button component instance at below of the stage with cheap levitra generic name “saveDrawing” and set its label to “download your sketch”.

    2. created a folder named as “flexScript” and put the below class into it.

    3. download corelib from google code and put it JPEGEncoder class at the path of : com.adobe.images.

    4. set the document class as “flexScript.flexScript.savejpgTest”

    5. hit ctrl+enter……… look at the magic

    package flexScript {
        import flash.display.Sprite;
        import flash.events.MouseEvent;
        import com.adobe.images.JPGEncoder;
        import flash.net.FileReference;
        import flash.display.*;
        import flash.events.*;
        import flash.utils.ByteArray;
    
        public class savejpgTest extends Sprite {
            private var jagFileRefSave:FileReference   = new FileReference();
              private var increment:Number=1;
              private var drawCanvas:MovieClip = new   MovieClip()
        public function savejpgTest(){
            addChildAt(drawCanvas, 0);
            sketch();
              saveDrawing.addEventListener(MouseEvent.CLICK,     saveBtnPress);
        }
        private function sketch(){   
            drawCanvas.graphics.beginFill(0xFFFFFF);
              drawCanvas.graphics.drawRect(0, 0, 250, 210);
            drawCanvas.graphics.endFill();
    
            drawCanvas.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
            drawCanvas.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
            drawCanvas.addEventListener(MouseEvent.MOUSE_MOVE,     makeLine);   
        }       
        private   function startDrawing(event:MouseEvent):void{   
            drawCanvas.graphics.lineStyle(1,     0, 1);
            drawCanvas.graphics.moveTo(mouseX,   mouseY);
            drawCanvas.addEventListener(MouseEvent.MOUSE_MOVE,     makeLine);
        }
        private   function stopDrawing(event:MouseEvent):void{
            drawCanvas.removeEventListener(MouseEvent.MOUSE_MOVE,     makeLine);
        }
        private function makeLine(event:MouseEvent):void{
            drawCanvas.graphics.lineTo(mouseX, mouseY);
        }
    
        private function saveJPG(sourceClip:MovieClip,       jpgQuality:Number):void{
                  var jpgClip:BitmapData   = new BitmapData (sourceClip.width, sourceClip.height);
            jpgClip.draw(sourceClip);
              var jpgEncoder:JPGEncoder <a href="http://over50losingweight.com/images/">424 buy viagra</a>    = new JPGEncoder(jpgQuality);
              var jpgBytes:ByteArray = jpgEncoder.encode(jpgClip);
            jagFileRefSave.save(jpgBytes,&quot;image&quot;+increment+&quot;.jpg&quot;);
            increment++;
        }
        private function saveBtnPress(e:Event):void{   
            saveJPG(drawCanvas, 90);
        }
        }
    }
    

    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.

    Load external image in to swf file – Load image class

    Posted on June 3, 2010 by Sameera Thilakasiri

    Load external image in to swf file – Load image class

    package
    {
    	import         flash.display.Sprite;
    	import       flash.display.Loader;
    	import               flash.net.URLLoader;
    	import         flash.net.URLRequest;
    
    	public         class loadImg   extends Sprite
    	{
    		public   function loadImg()
    		{
    			init()
    		}
    
    		private function       init():void
    		{
    			var loader:Loader =   new Loader();
    			addChild(loader);
    			loader.load(new         URLRequest(“image.jpg”));
    		}
    	}
    }
    

    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.

    « go backkeep looking »