I have used the below logic repeatedly now for processing Flash Vars in my Flex 4 applications which others may find useful. In the example below I use it in a service class. Basically I define a custom value object with the flash var properties defined. I then loop through the available parameters in the loadParameters() method using a [Transient] array which returns the name of each parameter.
package com.newtriks.services
{
import com.newtriks.models.vo.APIData;
import flash.events.EventDispatcher;
import mx.core.FlexGlobals;
public class FlashVarsService extends EventDispatcher implements IExternalParametersService
{
public function FlashVarsService(){}
public function loadParameters():void
{
var flashVars:Object = FlexGlobals.topLevelApplication.parameters;
var data:APIData = new com.newtriks.models.vo.APIData();
var param:String;
var i:int;
var length:int = data.params.length-1;
for ( i = length; i>= 0; i -- )
{
param = data.params[i].toString();
if(flashVars[param] != null)
data[param] = flashVars[param];
else
data[param] = ""; // Simply populate a null param with an empty string
}
}
}
}
Which implements:
package com.newtriks.services
{
import flash.events.IEventDispatcher;
public interface IExternalParametersService
{
function loadParameters():void;
}
}
And the APIData Object looks like this:
package com.newtriks.models.vo
{
public class APIData
{
public var username:String = '';
public var role:String = '';
public var status:String = '';
public function APIData(){}
[Transient]
public function get params():Array
{
return ["username","role","status"];
}
}
}
And finally the actual Flash Vars in the html wrapper:
/** Flash Vars passed into Flex **/
var flashvars = {username:"newtriks",role:"admin",status:"1"};
How To Reset Default Folder Icons on Mac OS X
I have recently installed a new SSD into my Mac Pro and decided instead of moving my Home folder to a separate drive as I usually do, to optimise the speeds of the SSD I would simply shift the larger directories to a separate drive and setup symbolic links. This was all fine until I forgot to update the Music directory icon and staring at a plain folder icon slowly started to irritate me. However, a bigger irritation was that no matter what I used i.e. CandyBar or LiteIcon the default folder icon would not reset
So after digging around the default icon set was eventually found in /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources, I then dragged MusicFolderIcon.icns into a CandyBar icon set, dropped it into the quick drop window and then finally dragged the Music folder onto the quick drop window, BAM all done and back to default icon thank you very much.