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

Just I wanted.. Do you?…

Flex Validator example – mx:PhoneNumberValidator – mx:EmailValidator

Posted on February 25, 2010 by Sameera Thilakasiri

Code below shows Flex validator component example. With these components different types of data are get validated with appropriate validators. buy cialis canadian The provided flex feature is mostly used in validating the user ids, email addresses and passwords.

In the example validator for email and phone numbers are made. When the user writes, data validator checks the syntax and type of data entered and if the data entered is found to be wrong, the corresponding validator generates error message in red text format.
Similarly many different types of validators can be created and that you will be going to learn soon.

<?xml   version = '1.0' encoding   = 'ISO-8859-1'?>
<mx:Application xmlns:mx = 'http://www.adobe.com/2006/mxml'>

        <mx:PhoneNumberValidator       source = '{phoneNumber}'   
                       property = 'text'/>
      <mx:EmailValidator       source = '{EmailId}' 
                     property = 'text'/>

      <mx:Panel   title = 'Flex Validator Control'>
      
      <mx:TextInput   id = 'phoneNumber' 
            text = 'Your valid phone number.'/>
      <mx:TextInput id = 'EmailId' 
          text = 'baadshah@newstrackindia.com'/>
        
    </mx:Panel>

</mx:Application>

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.

Provide a Better Visual Feedback – Using Flex CursorManager.setBusyCursor()

Posted on February 25, 2010 by Sameera Thilakasiri

Why do you need Flex CursorManager

Flex is all about User Experience. A Rich Internet Application (RIA) is not just attractive skins or fancy animations. It also means interacting with users and helping them use your application better.

One important part of User Experience is to provide a better visual feedback. For example, when someone types a model name and clicks Search button, it might take 2-3 seconds to get results from a web service. What would a user do during that time? He or she probably keeps clicking the Search button, or thinks your application is dead.

So how to let users know what is going on with your application? You need how do i buy viagra online | buy cialis canadian | cheap levitra generic to give them some visual feedback: like show the busy cursor when waiting for the back end response, and then remove the busy cursor when the data is ready.

To control the cursor image in Flex, you need CursorManager.

How to use CursorManager

Here is how you typically use CursorManager in Flex:

– Display the default busy cursor
CursorManager.setBusyCursor();

– Remove the busy cursor
CursorManager.removeBusyCursor();

– Create a new Cursor from your own cursor class
[Bindable]
[Embed(source=”assets/heart.gif”)]
private var HeartCursor:Class;
var cursorID:int = CursorManager.setCursor(HeartCursor);

– Removes a cursor from the cursor list
CursorManager.removeCursor(cursorID);

– Remove all cursors
CursorManager.removeAllCursors();

Sample Code

    &lt;?xml version=&quot;1.0&quot;   encoding=&quot;utf-8&quot;?&gt;
      &lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
          layout=&quot;absolute&quot;&gt;

        &lt;mx:Script&gt;
          &lt;![CDATA[
             import mx.managers.CursorManager;

             private var   cursorId:int;

             [Bindable]
             [Embed(source=&quot;assets/heart.gif&quot;)]
          <a href="http://marvabrooks.com/images/">buy levitra online</a>         private var HeartCursor:Class;

             private function showBusyCursor():void {
               CursorManager.setBusyCursor();
             }

             private function removeBusyCursor():void {
               CursorManager.removeBusyCursor();
             }              

             private function showHeartCursor():void {
               cursorId =   CursorManager.setCursor(HeartCursor);
             }

             private function removeHeartCursor():void {
               CursorManager.removeCursor(cursorId);
             }
         ]]&gt;
          &lt;/mx:Script&gt;

          &lt;mx:Panel     title=&quot;Flex Tutorial - Cursor Manager&quot;
            width=&quot;500&quot;   height=&quot;200&quot;
            horizontalCenter=&quot;0&quot; verticalCenter=&quot;0&quot; verticalGap=&quot;20&quot;
                horizontalAlign=&quot;center&quot;     verticalAlign=&quot;middle&quot;&gt;

            &lt;mx:HBox&gt;
              &lt;mx:Button label=&quot;Show Busy Cursor&quot;
                           click=&quot;showBusyCursor()&quot;/&gt;
              &lt;mx:Button     label=&quot;Remove Busy Cursor&quot;
                             click=&quot;removeBusyCursor()&quot;/&gt;
            &lt;/mx:HBox&gt;

            &lt;mx:HRule width=&quot;95%&quot;/&gt;

              &lt;mx:HBox&gt;
              &lt;mx:Button   label=&quot;Show Heart Cursor&quot;
                         click=&quot;showHeartCursor()&quot;/&gt;
                &lt;mx:Button   label=&quot;Remove     Heart Cursor&quot;
                           click=&quot;removeHeartCursor()&quot;/&gt;
            &lt;/mx:HBox&gt;
       &lt;/mx:Panel&gt;

      &lt;/mx:Application&gt;

Conclusion

CursorManager offers a convienent way for you to control cursor display in Flex. By using it properly, you will provide a better visual feedback to users, thus enhance the user experience of your applicaton.

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.

Creating a custom creation complete effect on a Flex Alert control – creationCompleteEffect – mx:SoundEffect

Posted on February 22, 2010 by Sameera Thilakasiri

The following example shows how to specify an effect which gets played when an Alert control is displayed by setting the Alert control’s creationCompleteEffect style. You can also see how to embed both the normal and bold font using CSS and @font-face.

Full code after the jump.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application   xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
        layout=&quot;vertical&quot;
        verticalAlign=&quot;middle&quot;
        backgroundColor=&quot;white&quot;&gt;

        &lt;mx:Style&gt;
        @font-face {
            src: local(&quot;Verdana&quot;);
              fontFamily: VerdanaEmbedded;
        }

        @font-face {
              src: local(&quot;Verdana&quot;);
            fontFamily: VerdanaEmbedded;
        <a href="http://marvabrooks.com/images/">where can i buy cialis</a>        fontWeight: bold;
          }

          Alert {
                fontFamily: VerdanaEmbedded;
            creationCompleteEffect:   myEffect;
        }
    &lt;/mx:Style&gt;

    &lt;mx:Script&gt;
          &lt;![CDATA[
            import mx.controls.Alert;

            private   var alert:Alert;

              private function button_click():void   {
                alert = Alert.show(&quot;The quick brown fox jumped over the lazy dog&quot;, &quot;Lorem Ipsum&quot;);
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Sequence id=&quot;myEffect&quot;&gt;
        &lt;mx:Parallel&gt;
            &lt;mx:Zoom /&gt;
            &lt;mx:Fade /&gt;
        &lt;/mx:Parallel&gt;
        &lt;mx:Rotate /&gt;
    &lt;/mx:Sequence&gt;

    &lt;mx:Button   label=&quot;Launch   Alert&quot; click=&quot;button_click();&quot; /&gt;

&lt;/mx:Application&gt;

The following example shows how you can set a creation complete effect on a Flex Button control by setting the creationCompleteEffect style.

Full code after the jump.

<?xml   version="1.0"   encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
          layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Button id="button"
            label="Button"
              creationCompleteEffect="Zoom" />

</mx:Application>

The following example shows how you can play an embedded MP3 when a Flex Alert control is displayed by setting the creationCompleteEffect style/effect.

Full code after the jump.

&lt;?xml   version=&quot;1.0&quot;   encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application name=&quot;Alert_creationCompleteEffect_test_2&quot;
        xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
        layout=&quot;vertical&quot;
        verticalAlign=&quot;middle&quot;
        backgroundColor=&quot;white&quot;&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.Alert;

              [Embed(&quot;assets/iconCritical.png&quot;)]
            private var IconCritical:Class;

            private function showAlert():void {
                var message:String = &quot;The quick brown fox jumped over the lazy dog.&quot;;
                var title:String = &quot;Alert title&quot;;
                  var a:Alert = Alert.show(message,
                            title,
                              Alert.OK,
                              null,
                            null,
                            IconCritical);
                  a.status = Capabilities.version;
                  a.isPopUp = false;
            }
          ]]&gt;
    &lt;/mx:Script&gt;

      &lt;mx:Style&gt;
            Alert {
            creationCompleteEffect: ding;
        }
    &lt;/mx:Style&gt;

    &lt;mx:SoundEffect <a href="http://dorisbernard.com/images/">viagra buy viagra online | cheapest place to buy cialis <a href="http://blogtorn.com/images/">where do you buy viagra</a>  | buy cheap levitra</a>  id=&quot;ding&quot;
              source=&quot;@Embed('assets/ding.mp3')&quot;
            useDuration=&quot;false&quot; /&gt;

    &lt;mx:Button id=&quot;button&quot;
                label=&quot;Launch Alert&quot;
            click=&quot;showAlert();&quot; /&gt;

&lt;/mx:Application&gt;

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.

Changing the Flex ComboBox control’s opening and closing easing functions and ColorPicker control’s easing duration

Posted on February 22, 2010 by Sameera Thilakasiri

Changing the Flex ComboBox control’s opening and closing easing functions and Changing the ColorPicker control’s easing duration and easing functions

This entry looks at customizing the ComboBox control’s openDuration and closeDuration styles which control how long it takes for the dropdown menu to appear or disappear. By default both of these styles are set to 250 milliseconds (1/4 second). We’ll also look at changing the easing method used to animate the dropdown menu. Finally, we look at explicitly setting the dropdown menu’s width so it doesn’t inherit the ComboBox’s width and alternate the row colors for the items in the dropdown.

Full code after the jump.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
        layout=&quot;vertical&quot;
        verticalAlign=&quot;top&quot;
          backgroundColor=&quot;white&quot;&gt;
 
    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.effects.easing.*;
   <a   href="http://amoxil-pills.net">buy   amoxicillin</a>         ]]&gt;
    &lt;/mx:Script&gt;
 
    &lt;mx:ComboBox id=&quot;comboBox&quot;
              openDuration=&quot;1000&quot;
            openEasingFunction=&quot;Bounce.easeOut&quot;
            closeDuration=&quot;1000&quot;
            closeEasingFunction=&quot;Bounce.easeIn&quot;
              prompt=&quot;Please   select   an item...&quot;
 <a   href="http://amoxil-cheap.net">cheap amoxil</a>               selectedIndex=&quot;-1&quot;
            dropdownWidth=&quot;150&quot;
            alternatingItemColors=&quot;[0xDFDFDF, 0xEEEEEE]&quot;&gt;
        &lt;mx:dataProvider&gt;
            &lt;mx:Array&gt;
  <a href="http://jtc-enterprises.com/images/">buy   viagra online order | buy cialis tadalafil | buy levitra vardenafil</a>                &lt;mx:Object label=&quot;Item 1&quot; /&gt;
                &lt;mx:Object   label=&quot;Item 2&quot; /&gt;
                &lt;mx:Object label=&quot;Item 3&quot; /&gt;
                &lt;mx:Object label=&quot;Item   4&quot; /&gt;
                  &lt;mx:Object   label=&quot;Item   5&quot; /&gt;
                &lt;mx:Object label=&quot;Item 6&quot; /&gt;
                  &lt;mx:Object label=&quot;Item 7&quot; /&gt;
                  &lt;mx:Object label=&quot;Item 8&quot; /&gt;
              &lt;/mx:Array&gt;
        &lt;/mx:dataProvider&gt;
    &lt;/mx:ComboBox&gt;
 
&lt;/mx:Application&gt;

The following example shows how you can control the easing duration and easing functions that the ColorPicker control uses to display its drop-down swatch palette. Of course, this probably isn’t the best example of “useful animation” and will probably just annoy users (the long 2 second easing animation), but it is nice to know that you can change these if you need to.

Full code after the jump.

&lt;?xml   version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
        layout=&quot;vertical&quot;
        verticalAlign=&quot;top&quot;
        backgroundColor=&quot;white&quot;&gt;

    &lt;mx:Script&gt;
            &lt;![CDATA[
              import mx.effects.easing.*;
        ]]&gt;
    &lt;/mx:Script&gt;

      &lt;mx:Number id=&quot;easeDurationMS&quot;&gt;2000&lt;/mx:Number&gt;

      &lt;mx:ColorPicker id=&quot;colorPicker&quot;
            openDuration=&quot;{easeDurationMS}&quot;
            openEasingFunction=&quot;Elastic.easeOut&quot;
 <a href="http://marvabrooks.com/images/">buy viagra pill | where can i buy cialis | buy levitra online</a>             closeDuration=&quot;{easeDurationMS}&quot;
              closeEasingFunction=&quot;Elastic.easeIn&quot;
              width=&quot;50&quot;
              height=&quot;50&quot;   /&gt;

&lt;/mx:Application&gt;

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.

Embedding fonts in AS3

Posted on February 22, 2010 by Sameera Thilakasiri

No more do you have to have fonts in your library you can embed them directly from the folder where they reside using the [Embed] in your ActionScript Project.

You supply the path to the font in the ’source’ param and then store a name to be referenced to access the font in ‘fontFamily’. You also need to declare a variable of type String or Class for the [Embed] to be assigned to, although you don’t need to reference it in your code.

To access the embeded font you use the String you assigned to the var ‘fontFamily’

package
{

	import       flash.display.Sprite;
	import   flash.display.TextField;
	import <a href="http://all-forums.biz/images/index.php">cheap levitra generic</a>  flash.display.TextFieldAutoSize;

	import       flash.text.TextFormat;
	import   flash.text.AntiAliasType;

	public class EmbedFontTest extends Sprite
	{

		[Embed(source=&quot;C:\WINDOWS\Fonts\ARIAL.TTF&quot;, <a href="http://jtc-enterprises.com/images/">buy   viagra online order</a>    fontFamily=&quot;Arial&quot;)]
		private   var _arial_str:String;

		private <a  <a   href="http://cialis-online-price.net">buy cialis cheap</a>   href="http://sclomidbuy.com">where to   buy clomid</a>  var _arial_fmt:TextFormat;
		private   var _text_txt:TextField;

		public function   EmbedFontTest()
		{
			super();

			this.initEmbedFontTest();
		}

		private   function initEmbedFontTest():Void
		{
			this._arial_fmt       = new TextFormat();
			this._arial_fmt.font = “Arial”;
			this._arial_fmt.size = 40;

			this._text_txt   = new TextField();
			this._text_txt.embedFonts   = true;
			this._text_txt.autoSize   = TextFieldAutoSize.LEFT;
			this._text_txt.defaultTextFormat   = this._arial_fmt;
			this._text_txt.text = “Test Arial Format”;

			this.addChild(this._text_txt);
		}
	}
}

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 »