/ Published in: ActionScript
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
import mx.utils.Delegate;
dynamic class classes.MainController extends MovieClip
{
private var __xml:XML;
public var xmlPath:String = "xml/settings.xml";
private var __tiles:Array = new Array();
/** -----------------------------------------------------------
* Constructor
* -----------------------------------------------------------
*/
public function MainController(){
trace("Document Class loaded");
};
public static function main(target:MovieClip):Void {
target.__proto__ = MainController.prototype;
Function(MainController).apply(target, null);
};
private function onLoad():Void{
loadSettings();
};
/** -----------------------------------------------------------
* Properties
* -----------------------------------------------------------
*/
/** -----------------------------------------------------------
* Public Methods
* -----------------------------------------------------------
*/
/** -----------------------------------------------------------
* Private Methods
* -----------------------------------------------------------
*/
private function loadSettings():Void{
__xml = new XML();
__xml.ignoreWhite = true;
__xml.onLoad = Delegate.create(this, onXMLLoad);
__xml.load(xmlPath);
};
private function onXMLLoad(success:Boolean):Void{
if (success){
parseXML();
}
};
private function parseXML():Void{
__tiles = filterXMLAssocArray("tile", __xml.firstChild.childNodes);
};
// Filters specified tags from a supplied XML Node resource by tag name.
// Returns a new associative array with the filtered tags' attributes.
private function filterXMLAssocArray(filterNodeName:String, xmlNodes:Array):Array{
var tmpArray:Array = new Array();
for (var i:Number = 0; i<xmlNodes.length; i++){
if (xmlNodes[i].nodeName == filterNodeName){
tmpArray[i] = new Array();
tmpArray[i] = xmlNodes[i].attributes;
}
}
return tmpArray;
};
private function print_r( obj, indent ) {
if (indent == null) indent = "";
var out = "";
for ( item in obj ) {
if (typeof( obj[item] ) == "object" )
out += indent+"[" + item + "] => Object\n";
else
out += indent+"[" + item + "] => " + obj[item]+"\n";
out += print_r( obj[item], indent+" " );
}
return out;
}
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                