[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Casting XML from HTTPService

Posted on 2011-10-23
Medium Priority
Last Modified: 2012-05-12
I'm hoping someone can help - I've spent way too much time trying to get something to work.

I'm trying to setup a tree structure that the user can edit.  I want to use an itemrender and a few events to handle the edits.  The only way I've gotten this to work nicely is to feed the tree an object that is created by Flex at compile time.  What I need is the ability to read in the data at runtime.

If I use a MX:XML model, Flex casts the XML as an object and everything works perfectly.

What I can't figure out is how to read this same data from an HTTP Service call.  I've tried setting the result type to object, e4x, xml etc.  I've tried XMLList, XML, and Array Collections.

I need the XML  cast as an object in the same manner that Flex stores/compiles it using the <mx:XML> model.

Any ideas of thoughts?



<mx:XML id="treedata"  format="e4x">
		<top label="node 0">
			<row label="node 1">
				<row label="subnode 1"/>
			<row label="node 3"> </row>
			<row label="node 5"></row>

private function initCatalog(cat:Object):void {
				myTree.dataProvider = cat;



Open in new window

Question by:thebellman
  • 2
LVL 29

Accepted Solution

dgofman earned 2000 total points
ID: 37014337
When you defined a format e4x the results coming in XML if you would like to get top node(root) use a parent function.


Author Closing Comment

ID: 37014600
Thanks - Got it working.!

Author Comment

ID: 37014631
In case someone is looking for a similar solution - the code example is shown below.  This example provides a tree control, read from external XML and allows you to edit.


<?xml version="1.0"?>
<top label="Hello">
                  <row label="Does this work?">
                        <row label="subnode 1"/>
                  <row label="node 3"> </row>
                  <row label="node 5"></row>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
			import mx.events.IndexChangedEvent;
			import mx.events.ListEvent;
			import mx.events.TreeEvent;
			//import Tree.TreeRenderer;
			import mx.controls.Alert;
			import mx.controls.TextInput;
			import comps.*;
			import mx.rpc.AsyncToken;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			import mx.rpc.http.HTTPService;
			import mx.utils.ObjectUtil;
			import mx.collections.XMLListCollection;
			[Bindable] public var remotetreedata:XML;
			//public var set:TreeRenderer;
			public var set_visible:Boolean=false;
			public var value:String;
			private function add_label(value:String):void
				// myTree.editedItemRenderer.data.@label=
				// nav.editedItemPosition={rowIndex:event.rowIndex}
			private function initCatalog(cat:Object):void {
				myTree.dataProvider = cat;
				trace ("My provider:" + myTree.dataProvider);
			// Define the event listener for the itemEditBeginning event
			// to disable editing when the user selects
			// the top node in the tree.
			private function disableEditing(event:ListEvent):void {
				if(event.rowIndex==0) {
			// Define the event listener for the itemEditEnd event
			// to copy the updated data back to the data provider
			// of the Tree control.
			public function processData(event:ListEvent):void {
				// Disable copying data back to the control.
				// Get new phone number from editor.
				myTree.editedItemRenderer.data.@label =
				// Get new status from editor.
				// Close the cell editor.
				// myTree.destroyItemEditor();
				// Notify the list control to update its display.
			private function loadXMLData():void {
				var httpService:HTTPService = new HTTPService();
			httpService.url = "xml/sample.xml" ;
			httpService.resultFormat = "e4x";
			httpService.addEventListener(FaultEvent.FAULT, httpService_fault);
			httpService.addEventListener(ResultEvent.RESULT, httpService_result);
			private function httpService_fault(evt:FaultEvent):void {
				var title:String = evt.type + " (" + evt.fault.faultCode + ")";
				var text:String = evt.fault.faultString;
			private function httpService_result(evt:ResultEvent):void {
				trace ('Made it here');
				remotetreedata  = XML(evt.result) ;
				trace('The object:' + ObjectUtil.toString(remotetreedata));

	<mx:Tree id="myTree"
			 width="400" height="400"
			 editorHeightOffset="2" editorWidthOffset="-225"
			 editorXOffset="49" editorYOffset="25"
			 itemEditEnd="processData(event);" labelField="@label"/>
	<mx:Button x="524" y="120" label="Button" id="btn_add"

Open in new window

<?xml version="1.0" encoding="utf-8"?>
<!-- itemRenderers\sparkmx\myComponents\MyTreeItemRenderer.mxml -->
<s:MXTreeItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
					  width="267" height="164" creationComplete="init();" >
			import mx.collections.*;
			import mx.controls.Tree;
			import mx.controls.treeClasses.*;
			public var newCategory:String;
			private function init ():void {
				labelDisplay.text = treeListData.label;

			// Override the set method for the data property
			// to set the font color and style of each node.    
			private function close ():void {
				var tree:Tree = listData.owner as Tree;
				tree.editedItemPosition = null;
				tree.selectedIndex = -1;
	<s:Panel x="10" y="10" width="250" height="131">
			<s:Label id="labelDisplay" x="25" y="10"/>
			<s:TextInput id="_foo" x="74" y="9" width="150" text='hello' />
			<s:Button x="1" y="67" label="Save it!" click="close();"/>
		<s:Button x="178" y="67" label="Cancel" click="parentDocument.mytree.destroyItemEditor(); "/>

Open in new window


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question