How to get/process the Data from XMLSocket?
hello all,
i'm using adobe professional cs6, , actionscript 3.0.
to start have c# program feeds data out server in form of xml data. have flash program should receive data , i'll stuff it. had working in actionscript 1.0 need upgrade code actionscript 3.0, instead of trying convert stuff on new actionscript version, i'm going re-write program.
so far i've defined eventlisteners of found examples of online using xmlsockets. of flash program connect xmlsocket server feeding out data, , server feeding data resends new data every 5-10 seconds or so.
so when grouping of xml data comes in on port defined, following function gets executed handling incoming data. eventlistener's function "socket.addeventlistener(dataevent.data, datahandler);" ("socket" defined --> var socket = new xmlsocket(); ). when new data comes in executes above function.
the trouble i'm having declaring new variable of type "xml" and using variable pull out individual "nodes/children" incoming xml data. found example online close want except instead of using xmlsocket data streaming in use "urlloader" function xml data. know i'm receiving xml data onto server because if set (e: dataevent) variable defined in function "head" string , run trace on can see of xml data in the "output window".
but can't seem able set (e: dataevent) xml variable can access individual elements of xml data. example found (which uses urlloader instead) uses line (myxml = new xml(e.target.data);) set xml variable, won't work mine, , if try same thing in code prints many lines there xml data --> "[object xmlsocket]"
my code:
*i left out other functions in code eventlisteners you'll see defined below, except 1 in question:
---> "function datahandler(e: dataevent):void"
import flash.events.ioerrorevent;
import flash.events.progressevent;
import flash.events.securityerrorevent;
import flash.events.dataevent;
var socket = new xmlsocket();
socket.addeventlistener(event.connect, connecthandler);
socket.addeventlistener(event.close, closehandler);
socket.addeventlistener(dataevent.data, datahandler);
socket.addeventlistener(ioerrorevent.io_error, ioerrorhandler);
socket.addeventlistener(progressevent.progress, progresshandler);
socket.addeventlistener(securityerrorevent.security_error, securityerrorhandler);
var success = socket.connect('server.domain.name.local',3004);
/*
the code in function used example found online described above in post:
link --> http://www.republicofcode.com/tutorials/flash/as3xml/
*/
// commented out code (*in blue) show xml data inside "output window":
function datahandler(e: dataevent):void {
// var mystr:string = e.data;
var xml:xml;
xml = new xml(e.target.data); //<--- doesn"t work (i dont think 'target' correct here)??
if (socket.connected)
{
// trace(mystr)
trace(xml);
}
}
the output line "trace(xml)" show data below in "output window" (*fyi there should 6 lines of xml data on each 'update'):
[object xmlsocket]
[object xmlsocket]
[object xmlsocket]
[object xmlsocket]
[object xmlsocket]
[object xmlsocket]
could show or point me in right direction on this. want able access specific parts of incoming xml data.
here's sample xml data:
<message var="screen2display" text="csq_1" />
<message var="f1_agentsready" text="111" />
<message var="f1_unavailableagents" text="222" />
<message var="f1_talkingagents" text="333" />
<message var="f1_callshandled" text="444" />
<message var="f1_abdrate" text="555" />
any thoughts or suggestions appreciated..!
fyi:
i'm new actionscript/flash developing (*about week now), go easy on me haha...
thanks in advance,
matt
based on dataevent documentation
http://help.adobe.com/en_us/flashplatform/reference/actionscript/3/flash/events/dataevent. html
looks need read data property on event:
var xml:xml = new xml(e.data) - not e.target.data
More discussions in ActionScript 3
adobe
Comments
Post a Comment