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));