setting properties at runtime from xml or css

Mainly this is just a post to remind myself in later times about this code snippet but basically this will work with any class with accessible variables.

Take an xml node such as

You can use this snippet to parse through those attributes to set all of your variables for you assuming they exist in your class.

public function setPropertiesFromXML(xmlNode:XML):void
	for each (var obj:XML in xmlNode.@*)
		//check for hex color before setting
		var strValue:String = obj.toString().replace('#', '0x');
		if( hasOwnProperty( ) this[] = (strValue=="false") ? false : strValue;
, , ,

Leave a Reply