Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-28-2012, 11:19 PM   #1
Trent Harris
Registered User
 
Join Date: May 2012
Posts: 8
Default [AS3] Post Trace Data to Datagrid in Flash CS4

Hello Everyone-

I am stuck on a problem and was wondering if anyone could point me in the right direction. I have a flash swf that reads xml data. Below is the code that reads the external xml file and parses it based on user ID.

The results are correct and show in the output window. I am stuck on how to get those trace results to load into a datagrid for view. Can anyone help with this?

Trent



var myLoader:URLLoader = new URLLoader;
var xmlData = new XML();

myLoader.addEventListener(Event.COMPLETE, LoadXML);
myLoader.load(new URLRequest("XML_WIN_Data.xml"));


function LoadXML(e:Event):void {
xmlData=new XML(e.target.data);
parse(xmlData);
}

function parse(Input:XML):void {
var dataroot:XMLList=Input.XML_WIN_Data.children();
var Attributes:XMLList=Input.XML_WIN_Data.attributes() ;
var List:XMLList = Input.XML_WIN_Data.(employeeid == "0101554");
trace(List);
}
Trent Harris is offline   Reply With Quote
Old 05-29-2012, 12:28 AM   #2
Sonny
Senior Member
 
Join Date: Aug 2010
Location: Sydney,Australia
Posts: 132
Default

help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/controls/DataGrid.html
Have a look at that and see the example. They explain something about a dataprovider
and how to set the columns in the datagrid . That is how you get it into a datagrid
Sonny is offline   Reply With Quote
Old 05-29-2012, 02:58 AM   #3
Trent Harris
Registered User
 
Join Date: May 2012
Posts: 8
Default

The site has a lot of data in it, but I am not sure were to really begin. do you know of any samples that would show how to put together the next step in moving the parsed data to the datagrid. I have tried a couple methods, but have yet to succeed.
Trent Harris is offline   Reply With Quote
Old 05-29-2012, 03:28 AM   #4
Sonny
Senior Member
 
Join Date: Aug 2010
Location: Sydney,Australia
Posts: 132
Default

ActionScript Code:
var dp:DataProvider = new DataProvider(); var totalEntries:uint = 42; var i:uint; for(i=0; i<totalEntries; i++) {     dp.addItem( {     col1:"CellName",                     col2:"CellName",                     col3:"CellName" } );            } var dg:DataGrid = new DataGrid(); dg.columns = [ "col1", "col2", "col3" ]; dg.editable = true; dg.dataProvider = dp; dg.move(200,10); dg.setSize(200,300); addChild(dg);

That is the part that creates the data and loads the datagrid. ..Modify that to suit your requirements
Sonny is offline   Reply With Quote
Old 06-01-2012, 02:31 AM   #5
Trent Harris
Registered User
 
Join Date: May 2012
Posts: 8
Default

I was able to get closer to getting this finished with the code provided. Thank you, but i still see to get an error, below is the code:

stop()

import fl.controls.DataGrid;
import fl.data.DataProvider;

var dpataProvider;
var myDataGridataGrid = new DataGrid();
myDataGrid.addColumn("employeeid");
myDataGrid.addColumn("type");
myDataGrid.addColumn("style");
myDataGrid.addColumn("size");
myDataGrid.addColumn("length");
myDataGrid.addColumn("assigndate");
myDataGrid.setSize(200, 200);
myDataGrid.width = 575;
myDataGrid.move(20, 20);
addChild(myDataGrid);




var myLoader:URLLoader = new URLLoader;
var xmlData = new XML();


myLoader.addEventListener(Event.COMPLETE, LoadXML);
myLoader.load(new URLRequest("XML_WIN_Data.xml"));


function LoadXML(e:Event):void {
xmlData=new XML(e.target.data);
parse(xmlData);
}

function parse(Input:XML):void {
var dataroot:XMLList=Input.XML_WIN_Data.children();
var Attributes:XMLList=Input.XML_WIN_Data.attributes() ;
var List:XMLList = Input.XML_WIN_Data.(employeeid == ID);
var xmlDP:XML = new XML(List.data)

dp = new DataProvider(xmlDP);
myDataGrid.dataProvider = dp;


}


The error message i get is the following:

TypeError: Error #1088: The markup in the document following the root element must be well-formed.
at test2_fla::MainTimeline/parse()
at test2_fla::MainTimeline/LoadXML()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

Is this something to do with the var calling the outputted XML file?
Trent Harris is offline   Reply With Quote
Old 06-01-2012, 04:04 AM   #6
Sonny
Senior Member
 
Join Date: Aug 2010
Location: Sydney,Australia
Posts: 132
Default

What is the structure of your xml.

if XML_WIN_Data is the root node of your xml you just use Input.children.

Here is a example

ActionScript Code:
function parse(Input:XML):void {     var list = Input;     trace("--- END 1 --- ");     var list2 = Input.children();     trace(list2);     trace("---- END 2 --- ");     var list3 = Input.employee.(@employeeid==1);     trace(list3);     trace("--- END 3 -- ");     for each (var xmlT in list3){         trace(xmlT.name);     } }
And the output.:: Follow the traces to see what happens
Original xml
Quote:
<?xml version="1.0" encoding="utf-8"?>
<XML_WIN_Data>
<employee employeeid="1">
<name>Sonny</name>
</employee>
<employee employeeid="2">
<name>Someonelese</name>
</employee>
</XML_WIN_Data>
Quote:
--- END 1 ---
<employee employeeid="1">
<name>Sonny</name>
</employee>
<employee employeeid="2">
<name>Someonelese</name>
</employee>
---- END 2 ---
<employee employeeid="1">
<name>Sonny</name>
</employee>
--- END 3 --
Sonny
Sonny is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:53 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.