call a function after few seconds using the method setTimeout().

December 28, 2007

In a Flex app if you want to call a function after sometime (in seconds or hours) you can use the method setTimeout().The below def shows the use.

setTimeout(getmyName,3000);

Here the method setTimeout() calls the function getmyName after 3 sec in the execution flow.i.e when the line setTimeout reaches in the excution flow then the execution flow calls the function getmyName after 3 sec as mentioned in the method.

The below code example explains the need.

import mx.managers.PopUpManager;
import flash.utils.setTimeout;
import mx.controls.Alert;
private var alert:Alert;
private function init():void
{
alert=Alert.show(“Hai”,”Kumar”);
setTimeout(hidealert,3000);
}
private function hidealert():void
{
PopUpManager.removePopUp(alert);
}

Here the function init() is called at creationComplete of the app.And it alerts and then waits for 3 sec and closes the Alert window as we are using the setTimeout method and calling a function to close the Alert using the PopUpManager class.

The method setTimeout() can used as our need in the app.leave any comments for suggestions.


Styles to DateField control.

December 28, 2007

The default style applied to the DateField control is OK but not upto the mark, we can edit this or change it using the property dateChooserStyleName of the DateField control.

The below code example will help you to define your  your own styles forDatField control.

<mx:DateField id=”dateField”
dateChooserStyleName=”subDateChooser” />

<mx:Style>
.subDateChooser {
backgroundColor: red;
color: white;
fontweight:bold
}
</mx:Style>

Nice property..!


Usable methods of DateField Class.

December 28, 2007

There are predefined methods for the Class DateField and they are very usefull when writing ur ActionScript.

For instance u want to know the day of the date you have mentioned in the date, this can be achevied by using the method getDate().For example the date is 28/12/2007 as below def.

private var date1=new Date();
date1=new Date(2007,11,28);

Now u want to know the day of that date variable date1.use the following line of code.

var d1=date1.getDate();

Now the variable d1 contains the day of the date variable date1.

similarly we can use the methods getMonth(),getYear(),getHours()[if u mention it in the date def],getMinutes() [if u mention it in the date def]….like that there are many methods i will come back with them later for instance have the following code.

private var date1=new Date();
private var date2=new Date();
private function init():void
{
date1=new Date(2007,11,28);
date2=new Date(2007,12,10);
}
private function show():void
{
var d1=date1.getDate();
var d2=date2.getDate();
Alert.show(” “+((30-d1)+(d2)),”SUM”);
}//similar for getmonth ,getyear, gethoures……..

<mx:Button label=”Button” click=”show()”/>

Here on click of button it alerts  the number of days in the given date range.

Similar code can be generated for other methods.