Thursday, June 7, 2012

Rounding a Decimal number to a given precision in Action sript

I found the below blog very useful for this problem
Truncating and Rounding Numbers in ActionScript 3

will also write something about it later

Setting all the dates before today as unsetectable in Date Field

If you want to have a date field where user is allowed to only select either today or any date after today you will have to use the disabledRanges property of Date filed like being used in the example below

<mx:DateField id="startDateForRAC" yearNavigationEnabled="true"
                    change="dateChanged(DateField("  width="91"
                     disabledRanges="{[ {rangeEnd: new Date(new Date().getFullYear(),new Date().getMonth(),new Date().getDate()-1)} ]}"
                    selectedDate="{new Date(today.getFullYear(), today.getMonth(), today.getDate())}" />

Note that only rangeEnd will be used to have a similar date field.

Tuesday, May 22, 2012

Changing the state of a check box by setting selected property to true will not call the change event

Strange , but I was assuming that if I set the  "selected" property of a CkeckBox in flex it will call the change event :) but it wont. Below is an example

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" 
layout="absolute" creationComplete="init()">
    < ![CDATA[
        import mx.controls.Alert;
        function checkBoxClicked():void{
  "Check box clicked");
        function init():void{
            cb.dispatchEvent(new MouseEvent(MouseEvent.CLICK));    
    ]] >
    <mx:CheckBox x="93" y="43" id="cb" label="Checkbox"

this didn't work , than I had to change the "init" function like below

        function init():void{
             cb.dispatchEvent(new MouseEvent(MouseEvent.CLICK));   

Note now I am pragmatically calling the mouse click event and to my surprise it worked , that's not good or am I missing something?

So Let's start looking in to the API documentation which states


Event Object Type:
property Event.type =
Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1
Dispatched when the selected property changes for a toggle Button control. A toggle Button control means that the toggle property is set to true. For the RadioButton controls, this event is dispatched when the selected property changes. For the CheckBox controls, this event is dispatched only when the user interacts with the control by using the mouse.

This is really strange but this is how things work in ActionScript.

Wednesday, May 16, 2012

Calling The MouseClick Event Programetically UsingAction Script

Let's say you have a button call myButton , you can use below line to call the Mouse Click or "click" event in Action Script

myButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));

Wednesday, May 11, 2011

Flex Date Problem

If you don't already know than there is a difference between American and British date formats
American is (Or American preferred Date format)mm/dd/yyyy (like 9/11/2003 or 9.1.2003)
While the British preferred date format isdd/mm/yyyy (like 11/9/2003 or 11.9.2003)

In Flex when you are creating a Date object by passing it the date String and if mistakenly you pass it date in British format it might show you unpredictable results, below is an example Date('15/11/2011').toDateString());will give you following date
Sun Mar 11 2012Of course this is not the date you wanted, and this is because flex was expecting data to be provided as mm/dd/yyyy but the data you provided was dd/mm/yyyy and surprisingly in this case flex will convert it into a wrong date.
So be carefull when you are supplying dates to Date class of action script and always make sure the date you are passing to it is in mm/dd/yyyy otherwise you will see unexpected results.

To understand my point here is another example
7/12/06, in American format , is July 12th, 2006 = 12 July 2006
7/12/06, In British format, is 7th December 2006 = 7 December 2006

Tuesday, April 28, 2009

Development in Flex and J2EE

I will share my experience in flex here , Those who just have started flex they can see a very good two article series at javajavaworld for getting started in flex

well i will keep updating this blog in future.