Return to Snippet

Revision: 3681
at August 30, 2007 13:02 by wintondeshong


Updated Code
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;
	}
}

Revision: 3680
at August 30, 2007 13:00 by wintondeshong


Updated Code
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;
	}
}

Revision: 3679
at August 30, 2007 12:57 by wintondeshong


Initial Code
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;
	}
}

Initial URL

                                

Initial Description

                                

Initial Title
Actionscript Document Class XML Load Template

Initial Tags
class, textmate, actionscript, template, xml, load

Initial Language
ActionScript