Nov 13 2009

How to loop through properties of a custom object/VO

If you just have a plain ol boring object, you can loop through it with a basic for…in:

var myObj:Object = {x:1, y:5};
for (var i:String in myObj)
{
    trace(i + ": " + myObj[i]);
}

However, if you have a custom value object, that doesn’t quite work. But what you can do is use describeType() to create an XMLList version on your VO.


var vo : SearchVO = data.getBody() as SearchVO;
// create an XMLList version of the VO
var varList:XMLList = describeType(vo)..variable;

// loop through the property list
for(var i:int; i < varList.length(); i++){
    // output the property name and value
    trace(varList[i].@name+':'+ vo[varList[i].@name]);
}

Post to Twitter


Nov 12 2009

Why is only one of my List (or Datagrid, Tree, etc.) rows selectable?

I remember hitting this before — after binding some data to a DataGrid (or any ListBase subclass) no matter where I rolled over the DataGrid only the last row was being highlighted.
After remembering that these ListBase classes rely on a unique id (uid) for each row/object, I started digging around and found that in my case, I was binding to VO’s which I had given a ‘uid’ property. This was interfering simply because I hadn’t yet hooked up that uid property so it wasn’t yet containing a unique id. So every row had the same unique id causing the DataGrid to essentially think it had only one row.
There are definitely other scenarios when something similar would happen. There’s more info here.

Post to Twitter


Nov 2 2009

Associative array of U.S. state codes

Just in case it’ll save anyone some time some day…


			var _stateCodes : Array = new Array();
			_stateCodes["AL"] = "Alabama";
			_stateCodes["AK"] = "Alaska";
			_stateCodes["AS"] = "American Somoa";
			_stateCodes["AZ"] = "Arizona";
			_stateCodes["AR"] = "Arkansas";
			_stateCodes["CA"] = "California";
			_stateCodes["CO"] = "Colorado";
			_stateCodes["CT"] = "Connecticut";
			_stateCodes["DE"] = "Delaware";
			_stateCodes["DC"] = "District Of Columbia";
			_stateCodes["FM"] = "Federated States of Micronesia";
			_stateCodes["FL"] = "Florida";
			_stateCodes["GA"] = "Georgia";
			_stateCodes["GU"] = "Guam";
			_stateCodes["HI"] = "Hawaii";
			_stateCodes["ID"] = "Idaho";
			_stateCodes["IL"] = "Illinois";
			_stateCodes["IN"] = "Indiana";
			_stateCodes["IA"] = "Iowa";
			_stateCodes["KS"] = "Kansas";
			_stateCodes["KY"] = "Kentucky";
			_stateCodes["LA"] = "Lousiana";
			_stateCodes["ME"] = "Maine";
			_stateCodes["MH"] = "Marshall Islands";
			_stateCodes["MD"] = "Maryland";
			_stateCodes["MA"] = "Massachussetts";
			_stateCodes["MI"] = "Michigan";
			_stateCodes["MN"] = "Minnesota";
			_stateCodes["MS"] = "Mississippi";
			_stateCodes["MO"] = "Missouri";
			_stateCodes["MT"] = "Montana";
			_stateCodes["NE"] = "Nebraska";
			_stateCodes["NV"] = "Nevada";
			_stateCodes["NH"] = "New Hampshire";
			_stateCodes["NJ"] = "New Jersey";
			_stateCodes["NM"] = "New Mexico";
			_stateCodes["NY"] = "New York";
			_stateCodes["NC"] = "North Carolina";
			_stateCodes["ND"] = "North Dakota";
			_stateCodes["MP"] = "Northern Mariana Islands";
			_stateCodes["OH"] = "Ohia";
			_stateCodes["OK"] = "Oklahoma";
			_stateCodes["OR"] = "Oregon";
			_stateCodes["PW"] = "Palau";
			_stateCodes["PA"] = "Pennsylvania";
			_stateCodes["PR"] = "Puerto Rico";
			_stateCodes["RI"] = "Rhode Island";
			_stateCodes["SC"] = "South Carolina";
			_stateCodes["SD"] = "South Dakota";
			_stateCodes["TN"] = "Tennessee";
			_stateCodes["TX"] = "Texas";
			_stateCodes["UT"] = "Utah";
			_stateCodes["VT"] = "Vermont";
			_stateCodes["VI"] = "Virgin Islands";
			_stateCodes["VA"] = "Virginia";
			_stateCodes["WA"] = "Washington";
			_stateCodes["WV"] = "West Virginia";
			_stateCodes["WI"] = "Wisconsin";
			_stateCodes["WY"] = "Wyoming";

Post to Twitter


Oct 24 2009

Embedding fonts in Flex 4

In Flex 3 I created a component where I needed to embed the fonts. I did so with:

[Embed(source='assets/fonts/ARIALBD.TTF', fontName='tabfont', fontWeight='bold')]

Until Flex 4 halo components use Flash Player 10 FTE based text (remembering that FTE is only compatible with CFF embedded fonts), you’ll have to also specify embedAsCFF=’false’ because the legacy Flash Player TextField based text cannot use CFF embedded fonts.

Additionally Spark skins for halo components now use the plain font instead of bold.

So now, to do the same in Flex 4, it’s:

[Embed(source='assets/fonts/ARIAL.TTF', embedAsCFF='false', fontName='tabfont')]

Post to Twitter


Oct 19 2009

Ruby on Rails extension for Flex 4

http://dcdror.riaforge.org/

Post to Twitter


Feb 10 2009

Actionscript 3- Vector to Array

There’s currently no way to convert a Vector to an Array (or ArrayCollection), so here’s a simple util that’ll do it. Accepts any type within the Vector, so the parameter is just an Object, then we convert it back to a vector before the Array conversion. Phew.

public static function VectorToArray( v:Object ):Array
{
    var vec : Vector. = Vector.(v);
    var arr : Array = new Array()
    for each( var i : Object in vec ) {
        arr.push(i);
    }
    return arr;
}

Post to Twitter


Apr 8 2008

Crossdomain.xml files in Rails projects

Usually when you need to allow a swf on one server access to data on another domain you would put a crossdomain.xml file in the root folder of that server.
I’ve found one exception which is if you are making a call to Rails the crossdomain.xml file to the ‘public’ folder of your Rails project.

Post to Twitter


Apr 2 2008

Flex and ColdFusion: RemoteObjects and WebServices

Once you have a ColdFusion CFC you can call it’s methods with a RemoteObject or via a WebService.
RemoteObjects are usually preferred for their performance speed.

Here we’ll create a super basic example of calling a CFC from both a WebService and a RemoteObject. The application will simply let you enter your name, click a button, call the CFC and return a welcome message including your name.

Continue reading

Post to Twitter


Mar 24 2008

Adobe Online Developer Week

Join us for the Adobe Online Developer Week which already under way!
http://adobe.com/go/2008_developer_week
There are a bunch of cool sessions about Flex, AIR, LCDS and more…

Post to Twitter


Feb 25 2008

Flex 3 and AIR 1.0 released!

Check ‘em out!
http://www.adobe.com/products/flex/
http://www.adobe.com/products/air/
And here’s a good New York Times article about AIR: Adobe Blurs Lines Between PC and Web

Post to Twitter