actionscript 3和xml的问题

时间:2010-06-22 14:19:10

标签: xml flash actionscript-3

我不小心偶然发现使用flash进行了一个不能选择php的项目,不幸的是我已经到了需要编辑一点动作的地步,而且它超出了我的范围。

xml看起来像这样(我知道它很愚蠢,但它已经绑定到一些php解析函数,这会让你重写!)

<project>
<project_1>
<name>Place name</name>
<other>sample</other>
</project_1>

<project_2>
<name>Place name</name>
<other>paragraph of text</other>
</project_2>

</project> 

我正在尝试从flash xml编辑器2编辑界面,下面是相关代码。我需要在节点名称后面包含名称文本,因此它会在编辑器的相关选项卡上读取project_2 Place name。我试过的编辑被评论。任何帮助将不胜感激!

汤姆

public class ClassicXMLNode extends MovieClip implements IEventDispatcher{
    public var XMLData:XML;
    public var isRoot:Boolean = false;
    public var num:Number;
    public var nodeName:String;
    public var nodePath:String;             // This will track the path throughout the XML document
    public var childrenNodes:XMLList;
    public var numNodes:uint;
    public var childHolder:MovieClip;
    public var isOpen:Boolean = false;      // Tracks whether the nodes data is opened or closed

    public static var moveDistance:Number; // This will be used for recursive loops : opening and closing sections

    public function ClassicXMLNode(Data:XML, nodeNum:Number, xmlPath:String = null) {           
        XMLData = Data;
        num = nodeNum;

        xmlPath ? nodePath = xmlPath : nodePath = "";
        nodeName = XMLData.name();
        nodePath += "." + nodeName;
        //trace(nodePath);

        addEventListener(Event.ADDED_TO_STAGE, addedListener);
    }

    public function addedListener(e:Event):void {
          //I added the var project

        var project:String = XMLData.project*.name.text();
        //Load the XMLData
            //and tried to concatenate it here

        nodeName_txt.text = XMLData.name + project();
        childrenNodes = XMLData.children();
        numNodes = childrenNodes.length();

        //Create the holder for childNodes
        childHolder = new MovieClip();
        childHolder.y = ClassicTree.nodeSpacing;
        childHolder.x = 50;
        addChild(childHolder);

        // Event Listeners
        openButton.buttonMode = true;
        openButton.tabEnabled = false;
        openButton.addEventListener(MouseEvent.CLICK, _click);
        numNodes == 0 ? openButton.visible = false : null;
        this.addEventListener(MouseEvent.MOUSE_OVER, hideActionMenu);
        this.addEventListener(MouseEvent.MOUSE_OUT, hideActionMenu);
        hideActionMenu();
        moveButtonCheck();
    }

2 个答案:

答案 0 :(得分:0)

我不确定这是否会有所帮助,但对我而言;我通常喜欢将我的XML转换为DataProvider(因为我几乎总是在一些消耗DataProviders的组件中使用它,因为它的内容)。

import fl.data.DataProvider;
function xmlParse(data:XML):DataProvider { 
    var dp:DataProvider;
    var i:uint;
    var obj:Object;
    var node:XML;

    dp = new DataProvider(); 

    for (i = 0; i < data.children().length(); i++) { 
        node = data.children()[i];

        obj = {
            branch: node.name(),
            name: node.name.text(),
            other: node.other.text()
        }

        dp.addItem(obj);
    }

    return dp;
}

var mydp:DataProvider = xmlParse(xml);
var item:Object = mydp.getItemAt(0);

for (var prop:String in item) { trace(prop, '->', item[prop]); }

答案 1 :(得分:0)

我刚刚想出来了,我删除了我添加的变量并编辑了这一行

nodeName_txt.text = XMLData.name() + XMLData.name.text()

获取节点名称,如果它有子名称,则添加该子文本。感谢所有看过的人和camdagr8!