2010-06-22 134 views
1

我意外地偶然發現了一個項目,其中PHP不是一個選項使用閃光燈,不幸的是我已經到了一個點,我需要編輯一個小動作,它超出了我。問題與actionscript 3和xml

的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> 

我想編輯從閃存中的XML編輯器的界面2,下面是相關的代碼。我需要在節點名稱後包含名稱文本,所以它會在編輯器的相關選項卡上讀取project_2地名。我試過的編輯已被評論。任何幫助將不勝感激!

湯姆

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(); 
    } 

回答

0

我不知道這是否會幫助,但對我來說,我通常喜歡將我的XML轉換爲DataProvider(因爲我幾乎總是在某些使用DataProvider的組件中使用它,因爲它的內容)。

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]); } 
+0

很酷,謝謝,看起來像一個更好的做事方式。不幸的是,我正在編輯一個更大的應用程序的一部分,所以它不太配合。我只是想了解它,但請看下面... :) – Tom 2010-06-23 11:26:59

0

我只是理解了它,現在,我放棄了我額外的增值經銷商和編輯這一行

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

它獲取節點名,如果它有一個孩子的名字「將添加孩子的文本。感謝所有看過camdagr8的人!