PDA

View Full Version : Attributes from XML into TextArea


billd
10-01-2007, 02:34 PM
Hi, I'm new here and new to Flex but excited about being able to develope apps using this program. My question is:
How do I populate the TextArea with external text files. I'm just pulling in the string.
My XML file looks like this:

<node label="Mail Box">
<node label="NetMail">
<node label = "Command Reviews" text = "doc.txt"/>
<node label="How to transfer a file using FTP"/>
<node label="Using i commands to see files at remote sites."/>
<node label="The f sho Command"/>
<node label="F Stats (F1 to F7)"/>
</node>
</node>

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="loadDataTree()">

<mx:HTTPService id="service"/>
<mx:TextArea data="{service.lastResult}"/>

<mx:Script><![CDATA[
[Bindable]public var _xmlData:XML;
[Bindable]private var _xmlCur:XML;

public function loadDataTree():void
{
var loader:URLLoader = new URLLoader(new URLRequest("data.xml"));
loader.addEventListener("complete",setTree);
"service.send();"
}

private function oChangeTree(oEvent:Event):void
{
_xmlCur = XML(oEvent.target.selectedItem); //set the bindable variable
_xmlData = XML(oEvent.target.selectedItem); //set the bindable variable
}
public function setTree(event:Event):void
{
var dataXML:XML = XML(event.target.data);
treeView.dataProvider=dataXML;
treeView.labelField = "@label";
}
]]></mx:Script>
<mx:HDividedBox x="10" y="0" width="100%" height="100%">
<mx:Tree id = "treeView" labelField = "@label"
change="oChangeTree(event)" height="651" width="276">
</mx:Tree>
<mx:TextArea text="{_xmlData.@text}"/>
<mx:TextArea text = "{_xmlCur.@label}" width="639" height="544">
</mx:TextArea>
</mx:HDividedBox>
</mx:Application>

Thanks for any help you can give me on this.

drkstr
10-01-2007, 10:33 PM
You can try something like this:

[Bindable]
private var myDocText:String;

private function oChangeTree(oEvent:Event):void {
_xmlCur = XML(oEvent.target.selectedItem); //set the bindable variable
_xmlData = XML(oEvent.target.selectedItem); //set the bindable variable

loadText(_xmlData.@text);
}

private function loadText( url:String ): void {
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(url);

loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, handleTextLoaded);
loader.load(request);
}

private function handleTextLoaded( event:Event ): void {
myDocText = String(event.target.data);
}

<mx:TextArea text="{myDocText}"/>

But there are many other ways to do it as well.

Best Regards,
...aaron

billd
10-02-2007, 01:44 PM
That worked out for me. Thanks again for the help.