Thursday, May 27, 2010

Flex Actionscript GoodNess: AS equivalent of Java Hashmap / Hashtable

With Java being the my core language, it always puzzles me why is there is not good Hashtable functionality..

There are lot of equivalents though, but I still miss the Java Hashtable.

Here are the Options

1. Associative Arrays

   1: var params:Array = new Array()
   2: params.firstName = txName.text
   3: params.lastName = txLName.text
   4: displayValues(params)
   6: public static const FIRST_NAME:String ="firstName"
   7: public static const LAST_NAME:String = "lastName"
   8: //Retreive values From Associative Array
   9: public function displayValues(params:Array):void{
  10:     var firstName:String = params[FIRST_NAME]
  11:     var lastName:String = params[LAST_NAME]
  12:     trace(firstName)
  13:     trace(lastName)
  14: }

2. flash.utils.Dictionary

   1: import flash.utils.Dictionary
   3: //Set values to dictionary
   4: public function dictionaryDemo(fName:String, lName:String):void{
   5:     var aDict:Dictionary = new Dictionary()
   6:     aDict.firstName = fName
   7:     aDict.lastName = lName
   8:      displayValues(aDict)
   9: }
  10: public function displayValues(aDict:Dictionary):void{
  11:     trace(aDict.firstName)
  12:     trace(aDict.lastName)
  14: //You can also iterate over a Dictionary
  15:     for (val in aDict) { 
  16:         trace ("KeyVal pair is " + val + " = " + aDict[val]); 
  17:     }
  18: }

What do you guys think, which one is better Associative Arrays or Dictionary..

By default, I have observed that actionscript Object type behaves like dictionary.

Friday, May 21, 2010

Started Using Windows Live Writer

For a while I was wondering on how to give more curb appeal to my blog , make it more attractive at the same time making it easy to upload images, links and tweeting about it.

Finally I stumbled upon Windows Live Writer which is Free and allows to write the blog , do the images, tweets, facebook and other social networking sites


Jellyfish This is a sample Jelly fish photo to demonstrate the photo ability

Windows writer seems to be a very good software to solve the Blogging issues and is a boon for Bloggers.

Some useful links to get more out of Windows Live Writer.

Five Things To Do After Installing Windows Live Writer

Seven great plugins for windows live writer


Wednesday, May 5, 2010

Flex Actionscript GoodNess :Changing States in Flex from ActionScript

States are a breeze in Flex4, they are so elegant and simple to use.

If you are using Cairngorm or other model, you are bound to change the State in Flex from Command Object through actionScript.

Here is how to change the states..

import mx.core.FlexGlobals

//then Navigate to the component in a top down hierarchy and change the //currentState property


Done!! Hurray!!

Flex Actionscript GoodNess: Updating Datagrid Display when Model(ArrayCollection) changes

Normally, making the dataProvider bindable makes sure, that if the underlying VO(Value Object) changes, the changes are reflected in the dataGrid.
But In case if the VO used cannot be made Bindable it becomes a problem, for e.g if the VO is a Dictionary Object.
In that case we need to notify the listeners of ArrayCollection that one of the VOs has changed, following code demostrates that.

var myDataArray:ArrayCollection = new ArrayCollection()

Lets Create the VOs to add to this collection
var empArr:Array = new Array()
var emp1:Dictionary = new Dictionary() ="john"

var emp2:Dictionary = new Dictionary() ="richard"

myDataArray = new ArrayCollection(empArr)

//Now lets set the dataProvider to the DataGrid

Now lets say if I go and update the emp1 Object, the value needs to get updated in
the DataGrid, but it will not unless I call itemUpdated() on the ArrayCollection.

Here is how I updated the DataGrid"UpdatedJohn"
myDataArray.itemUpdated(emp1) //And that will do the trick

Done!! Hurray!!

Tuesday, May 4, 2010

Flex Actionscript Goodness :Iterating Over Dictionary Object

import flash.utils.Dictionary

//Dictionary object is like key-value pair in Java, following is a code to iterate over //it

var myKeyValObj:Dictionary = new Dictionary()
myKeyValObj.firstName = "myfirstname"
myKeyValObj.lastName = "mylastname"

for (var name:String in myKeyValObj) {
trace ("myKeyValObj." + name + " = " + myKeyValObj[name]);

Done!! Hurray!!