Home ยป How to convert action script 2 to action script 3?

How to convert action script 2 to action script 3?

class XMLLoad extends EventDispatcher{
public var XML_NODE_TYPE_TEXT = 3;
public var XML_NODE_TYPE_ELEMENT = 1;
private var xmlPath:String;
private var xmlObj:Object;
private var classObj:Object;
private var data_xml:XML;
private var loadedxmldata:XML;
private var success:Boolean;

public static var LOAD_SUCCESS:String = “xmlObjCreated”;
public static var LOAD_FAILED:String = “xmlObjFailed”;

public function XMLLoad() {
    loadedxmldata = new XML();
    classObj = new Object();
}

public function setXMLObject(_xmlPath:String):Void {
    xmlPath = _xmlPath;
    data_xml = new XML();
    data_xml.ignoreWhite = true;
    data_xml.load(xmlPath)
    data_xml.onLoad = Proxy.create(this, loadXml, success, data_xml);
}

public function getLoadedXML():XML {
    return loadedxmldata;
}

private function loadXml(success):Void {
    if (success) {
        loadedxmldata = data_xml
        xmlObj = XMLDocToObject(data_xml);
        var eveObj:Object = {target:this, type:LOAD_SUCCESS, xmlObj:xmlObj, nativeXMLObj:data_xml}
        dispatchEvent(eveObj)
    } else {
        var eveObj:Object = {target:this, type:LOAD_FAILED, nativeXMLObj:data_xml}
        dispatchEvent(eveObj)
    }
}

public function XMLDocToObject(oXML):Array {
    var obj = [];
    if (oXML == null) {
        return obj;
    }
    var eRoot = oXML.firstChild;
    if (eRoot != null) {
        obj = buildObject(obj, eRoot);
    }
    return obj;
}

private function buildObject(obj, eItem):Array {
    var idx, eChild;
    var oTarget;
    while (eItem != null) {
        idx = eItem.nodeName;
        if (eItem.nodeType == XML_NODE_TYPE_ELEMENT) {
            oTarget = buildObject({}, eItem.firstChild);
            for (var attrib in eItem.attributes) {
                oTarget[attrib] = eItem.attributes[attrib];
            }
            if (eItem.nodeValue != null) {
                oTarget._value = eItem.nodeValue;
            } else {
                eChild = eItem.firstChild;
                if (eChild != null) {
                    if (eChild.nodeType == XML_NODE_TYPE_TEXT) {
                        if (eChild.nodeValue != null) {
                            oTarget._value = eChild.nodeValue;
                        }
                    }
                }
            }
        if (obj[idx]._type != ‘array’) {
            obj[idx] = [obj[idx]];
            obj[idx]._type = “array”;
            obj[idx][0] = oTarget;
        } else {
            obj[idx][obj[idx].length] = oTarget;
        }
    }

Add Comment

Click here to post a comment

Your email address will not be published. Required fields are marked *