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>
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
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
import mx.managers.CursorManager;
private var cursorId:int;
[Bindable]
[Embed(source="assets/heart.gif")]
<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);
}
]]>
</mx:Script>
<mx:Panel title="Flex Tutorial - Cursor Manager"
width="500" height="200"
horizontalCenter="0" verticalCenter="0" verticalGap="20"
horizontalAlign="center" verticalAlign="middle">
<mx:HBox>
<mx:Button label="Show Busy Cursor"
click="showBusyCursor()"/>
<mx:Button label="Remove Busy Cursor"
click="removeBusyCursor()"/>
</mx:HBox>
<mx:HRule width="95%"/>
<mx:HBox>
<mx:Button label="Show Heart Cursor"
click="showHeartCursor()"/>
<mx:Button label="Remove Heart Cursor"
click="removeHeartCursor()"/>
</mx:HBox>
</mx:Panel>
</mx:Application>
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.
Tags: CursorManager.removeCursor() | CursorManager.setCursor() | mx:HRule | setBusyCursor()
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.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Style>
@font-face {
src: local("Verdana");
fontFamily: VerdanaEmbedded;
}
@font-face {
src: local("Verdana");
fontFamily: VerdanaEmbedded;
<a href="http://marvabrooks.com/images/">where can i buy cialis</a> fontWeight: bold;
}
Alert {
fontFamily: VerdanaEmbedded;
creationCompleteEffect: myEffect;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private var alert:Alert;
private function button_click():void {
alert = Alert.show("The quick brown fox jumped over the lazy dog", "Lorem Ipsum");
}
]]>
</mx:Script>
<mx:Sequence id="myEffect">
<mx:Parallel>
<mx:Zoom />
<mx:Fade />
</mx:Parallel>
<mx:Rotate />
</mx:Sequence>
<mx:Button label="Launch Alert" click="button_click();" />
</mx:Application>
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.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application name="Alert_creationCompleteEffect_test_2"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
[Embed("assets/iconCritical.png")]
private var IconCritical:Class;
private function showAlert():void {
var message:String = "The quick brown fox jumped over the lazy dog.";
var title:String = "Alert title";
var a:Alert = Alert.show(message,
title,
Alert.OK,
null,
null,
IconCritical);
a.status = Capabilities.version;
a.isPopUp = false;
}
]]>
</mx:Script>
<mx:Style>
Alert {
creationCompleteEffect: ding;
}
</mx:Style>
<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="ding"
source="@Embed('assets/ding.mp3')"
useDuration="false" />
<mx:Button id="button"
label="Launch Alert"
click="showAlert();" />
</mx:Application>
Tags: Alert.show | creationCompleteEffect | mx:Parallel | mx:Rotate | mx:Sequence | mx:SoundEffect | mx:Zoom
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.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="top"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.effects.easing.*;
<a href="http://amoxil-pills.net">buy amoxicillin</a> ]]>
</mx:Script>
<mx:ComboBox id="comboBox"
openDuration="1000"
openEasingFunction="Bounce.easeOut"
closeDuration="1000"
closeEasingFunction="Bounce.easeIn"
prompt="Please select an item..."
<a href="http://amoxil-cheap.net">cheap amoxil</a> selectedIndex="-1"
dropdownWidth="150"
alternatingItemColors="[0xDFDFDF, 0xEEEEEE]">
<mx:dataProvider>
<mx:Array>
<a href="http://jtc-enterprises.com/images/">buy viagra online order | buy cialis tadalafil | buy levitra vardenafil</a> <mx:Object label="Item 1" />
<mx:Object label="Item 2" />
<mx:Object label="Item 3" />
<mx:Object label="Item 4" />
<mx:Object label="Item 5" />
<mx:Object label="Item 6" />
<mx:Object label="Item 7" />
<mx:Object label="Item 8" />
</mx:Array>
</mx:dataProvider>
</mx:ComboBox>
</mx:Application>
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.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="top"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.effects.easing.*;
]]>
</mx:Script>
<mx:Number id="easeDurationMS">2000</mx:Number>
<mx:ColorPicker id="colorPicker"
openDuration="{easeDurationMS}"
openEasingFunction="Elastic.easeOut"
<a href="http://marvabrooks.com/images/">buy viagra pill | where can i buy cialis | buy levitra online</a> closeDuration="{easeDurationMS}"
closeEasingFunction="Elastic.easeIn"
width="50"
height="50" />
</mx:Application>
Tags: closeEasingFunction | import mx.effects.easing.* | openDuration | openEasingFunction
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="C:\WINDOWS\Fonts\ARIAL.TTF", <a href="http://jtc-enterprises.com/images/">buy viagra online order</a> fontFamily="Arial")]
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);
}
}
}
« go back — keep looking »
Sameera at LinkedIn
