⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fieldaccessor.as

📁 如遇MD5加密文件
💻 AS
📖 第 1 页 / 共 2 页
字号:
class mx.data.binding.FieldAccessor
{
    var component, property, parentObj, fieldName, m_location, type, index, xpath, data;
    function FieldAccessor(component, property, parentObj, fieldName, type, index, parentField)
    {
        this.component = component;
        this.property = property;
        this.parentObj = parentObj;
        this.fieldName = fieldName;
        if (component == parentObj)
        {
            m_location = undefined;
        }
        else if (parentField.m_location == undefined)
        {
            m_location = fieldName;
        }
        else
        {
            m_location = parentField.m_location + "." + fieldName;
        } // end else if
        this.type = type;
        this.index = index;
    } // End of the function
    function getValue()
    {
        var _loc2 = this.getFieldData();
        if (_loc2 == null && type.value != undefined)
        {
            var _loc3 = new mx.data.binding.TypedValue(type.value, "String");
            _loc3.getDefault = true;
            component.getField(fieldName).setAnyTypedValue(_loc3);
            _loc2 = _loc3.value;
        } // end if
        if (this.isXML(_loc2) && _loc2.childNodes.length == 1 && _loc2.firstChild.nodeType == 3)
        {
            return (_loc2.firstChild.nodeValue);
        }
        else
        {
            return (_loc2);
        } // end else if
    } // End of the function
    function setValue(newValue, newTypedValue)
    {
        if (newTypedValue.getDefault)
        {
            newTypedValue.value = newValue;
        }
        else
        {
            if (xpath != null)
            {
                var _loc5 = this.getFieldData();
                if (_loc5 != null)
                {
                    mx.data.binding.FieldAccessor.setXMLData(_loc5, newValue);
                }
                else
                {
                    _global.__dataLogger.logData(component, "Can\'t assign to \'<property>:<xpath>\' because there is no element at the given path", this);
                } // end else if
            }
            else if (this.isXML(parentObj))
            {
                if (type.category == "attribute")
                {
                    parentObj.attributes[fieldName] = newValue;
                }
                else if (type.category == "array")
                {
                }
                else
                {
                    _loc5 = this.getOrCreateFieldData();
                    mx.data.binding.FieldAccessor.setXMLData(_loc5, newValue);
                } // end else if
            }
            else
            {
                if (parentObj == null)
                {
                    _global.__dataLogger.logData(component, "Can\'t set field \'<property>/<location>\' because the field doesn\'t exist", this);
                } // end if
                parentObj[fieldName] = newValue;
            } // end else if
            component.propertyModified(property, xpath == null && parentObj == component, newTypedValue.type);
        } // end else if
    } // End of the function
    static function isActionScriptPath(str)
    {
        var _loc2 = str.toLowerCase();
        var _loc3 = "0123456789abcdefghijklmnopqrstuvwxyz_.";
        for (var _loc1 = 0; _loc1 < _loc2.length; ++_loc1)
        {
            if (_loc3.indexOf(_loc2.charAt(_loc1)) == -1)
            {
                return (false);
            } // end if
        } // end of for
        return (true);
    } // End of the function
    static function createFieldAccessor(component, property, location, type, mustExist)
    {
        if (mustExist && component[property] == null)
        {
            _global.__dataLogger.logData(component, "Warning: property \'<property>\' does not exist", {property: property});
            return (null);
        } // end if
        var _loc5 = new mx.data.binding.FieldAccessor(component, property, component, property, type, null, null);
        if (location == null)
        {
            return (_loc5);
        } // end if
        var _loc7 = null;
        if (location.indices != null)
        {
            _loc7 = location.indices;
            location = location.path;
        } // end if
        if (typeof(location) == "string")
        {
            if (_loc7 != null)
            {
                _global.__dataLogger.logData(component, "Warning: ignoring index values for property \'<property>\', path \'<location>\'", {property: property, location: location});
            } // end if
            if (mx.data.binding.FieldAccessor.isActionScriptPath(String(location)))
            {
                location = location.split(".");
            }
            else
            {
                _loc5.xpath = location;
                return (_loc5);
            } // end if
        } // end else if
        if (location instanceof Array)
        {
            var _loc3;
            var _loc11 = 0;
            for (var _loc3 = 0; _loc3 < location.length; ++_loc3)
            {
                var _loc2 = null;
                var _loc4 = location[_loc3];
                if (_loc4 == "[n]")
                {
                    if (_loc7 == null)
                    {
                        _global.__dataLogger.logData(component, "Error: indices for <property>:<location> are null, but [n] appears in the location.", {property: property, location: location});
                        return (null);
                    } // end if
                    _loc2 = _loc7[_loc11++];
                    if (_loc2 == null)
                    {
                        _global.__dataLogger.logData(component, "Error: not enough index values for <property>:<location>", {property: property, location: location});
                        return (null);
                    } // end if
                } // end if
                _loc5 = _loc5.getChild(_loc4, _loc2, mustExist);
            } // end of for
            if (mustExist && _loc5.getValue() == null)
            {
                _global.__dataLogger.logData(component, "Warning: field <property>:<m_location> does not exist, or is null", _loc5);
            } // end if
            return (_loc5);
        }
        else
        {
            trace ("unrecognized location: " + mx.data.binding.ObjectDumper.toString(location));
            return (null);
        } // end else if
    } // End of the function
    function getFieldAccessor()
    {
        return (this);
    } // End of the function
    function getChild(childName, index, mustExist)
    {
        if (childName == ".")
        {
            return (this);
        } // end if
        var _loc2 = this.getOrCreateFieldData(mustExist);
        if (_loc2 == null)
        {
            return (null);
        } // end if
        var _loc4 = mx.data.binding.FieldAccessor.findElementType(type, childName);
        return (new mx.data.binding.FieldAccessor(component, property, _loc2, childName, _loc4, index, this));
    } // End of the function
    function getOrCreateFieldData(mustExist)
    {
        var _loc3 = this.getFieldData();
        if (_loc3 == null)
        {
            if (mustExist)
            {
                _global.__dataLogger.logData(component, "Warning: field <property>:<m_location> does not exist", this);
            }
            else
            {
                this.setupComplexField();
                _loc3 = this.getFieldData();
            } // end if
        } // end else if
        return (_loc3);
    } // End of the function
    function evaluateSubPath(obj, type)
    {
        var path = type.path;
        if (mx.data.binding.FieldAccessor.isActionScriptPath(path))
        {
            var tokens = path.split(".");
            var i = 0;
            while (i < tokens.length)
            {
                var token = tokens[i];
                if (this.isXML(obj))
                {
                    for (obj = obj.firstChild; obj != null; obj = obj.nextSibling)
                    {
                        if (mx.data.binding.FieldAccessor.toLocalName(obj.nodeName) == token)
                        {
                            break;
                        } // end if
                    } // end of for
                }
                else
                {
                    obj = obj[token];
                } // end else if
                if (obj == null)
                {
                    _global.__dataLogger.logData(this.component, "Warning: path \'<path>\' evaluates to null, at \'<token>\' in <t.property>:<t.m_location>", {path: path, token: token, t: this});
                    break;
                } // end if
                ++i;
            } // end while
        }
        else if (this.isXML(obj))
        {
            if (path.charAt(0) != "/")
            {
                path = "/" + path;
            } // end if
            path = mx.data.binding.FieldAccessor.toLocalName(obj.nodeName) + path;
            var category = type.category != null ? (type.category) : (type.elements.length > 0 ? ("complex") : ("simple"));
            if (category == "simple" || category == "attribute")
            {
                obj = eval("obj" + mx.xpath.XPathAPI.getEvalString(obj, path));
            }
            else if (category == "complex")
            {
                obj = mx.xpath.XPathAPI.selectSingleNode(obj, path);
            }
            else if (category == "array")
            {
                obj = mx.xpath.XPathAPI.selectNodeList(obj, path);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -