views:

51

answers:

2

Hi,

I accidentally stumbled into using flash for a project where php wasn't an option, unfortunately I've come to a point where i need to edit a little actionscript and it's beyond me.

the xml looks like this (i know it's stupid but it's already tied into some php parsing functions that would be irritating to rewrite!)

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

I'm trying to edit an interface from flash xml editor 2, below is the relevant code. I need to include the name text after the node name, so it would read project_2 Place name on the relevant tab in the editor. The edit i've attempted is commented. Any help would be greatly appreciated!

Tom

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

I'm not sure if this will help, but for me; I typically like to convert my XML into a DataProvider (because I almost always use it in some component that consumes DataProviders as it's content).

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]); }
camdagr8
cool, thanks, looks like a better way of doing things. Unfortunately I'm editing part of a larger application so it doesn't quite tie in. I've just about figured it out now though, see below... :)
Tom
A: 

I've just about figured it out now, I dropped my added vars and edited this line

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

which gets the node name and if it has a child 'name' will add that childs text. Thanks to all who took a look and to camdagr8!

Tom