swf listens to XML, AS3
Posted
by VideoDnd
on Stack Overflow
See other posts from Stack Overflow
or by VideoDnd
Published on 2010-03-15T20:37:18Z
Indexed on
2010/03/15
20:39 UTC
Read the original article
Hit count: 341
My swf listens to XML from a socket and document. How do I get 'my variables' to grab XML from the socket instead of the XML document?
PURPOSE
My purpose is to control variables with a XML Socket Server. I hope my question is clear, but ask if there's any questions.
EXAMPLE
Flash File
import flash.net.*;
import flash.display.*;
import flash.events.*;
import flash.system.Security;
import flash.utils.Timer;
import flash.events.TimerEvent;
//MY VARIABLES, LINE 8-12
var timer:Timer = new Timer(10);
var myString:String = "";
var count:int = 0;
var myStg:String = "";
var fcount:int = 0;
var xml_s=new XMLSocket();
xml_s.addEventListener(Event.CONNECT, socket_event_catcher);//OnConnect//
xml_s.addEventListener(Event.CLOSE, socket_event_catcher);//OnDisconnect//
xml_s.addEventListener(IOErrorEvent.IO_ERROR, socket_event_catcher);//Unable To Connect//
xml_s.addEventListener(DataEvent.DATA, socket_event_catcher);//OnDisconnect//
xml_s.connect("localhost", 1999);
function socket_event_catcher(Event):void {
switch (Event.type) {
case 'ioError' :
trace("ioError: " + Event.text);//Unable to Connect :(//
break;
case 'connect' :
trace("Connection Established!");//Connected :)//
break;
case 'data' :
trace("Received Data: " + Event.data);
//var myXML:XML=new XML(Event.data);
//trace("myXML.body.file: " + myXML.body.file);
//var myLoader:String=myXML.body.file;
//var urlReq:URLRequest=new URLRequest(myLoader);
//trace("file to load URL: " + urlReq);
break;
case 'close' :
trace("Connection Closed!");//OnDisconnect :( //
xml_s.close();
break;
}
}
//LOAD XML
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("time.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
//var myXML:XML=new XML(Event.data);
//trace("myXML.body.file: " + myXML.body.file);
//var DOINK:String=myXML.body.file;
//var urlReq:URLRequest=new URLRequest(DOINK);
//trace("file to load URL: " + urlReq);
//PARSE XML
function processXML(e:Event):void {
myXML = new XML(e.target.data);
trace(myXML.COUNT.text()); //-77777
//grab the data as a string
myString = myXML.COUNT.text()
//grab the data as an int
count = int(myXML.COUNT.text());
//grab the data as a string
myString = myXML.COUNT.text()
//grab the data as an int
count = int(myXML.COUNT.text());
//grab the data as a string
myStg = myXML.COUNT.text()
//grab the data as an int
fcount = int(myXML.COUNT.text());
//grab the data as a string
myStg = myXML.COUNT.text()
//grab the data as an int
fcount = int(myXML.COUNT.text());
trace("String: ", myString);
trace("Int: ", count);
trace(count - 1); //just to show you that it's a number that you can do math with (-77778)
//TEXT
var text:TextField = new TextField();
text.text = myString;
addChild(text);
}
Ruby Server 'Snippet'
msg1 = {"msg" => {"head" => {"type" => "frctl", "seq_no" => seq_no, "version" => 1.0},
"SESSION" => {"text" => "88888", "timer" => -1000,
"count" => 10, "fcount" => "10"}}}
XML
<?xml version="1.0" encoding="utf-8"?>
<SESSION>
<TIMER TITLE="speed">100</TIMER>
<COUNT TITLE="starting position">88888</COUNT>
<FCOUNT TITLE="ramp">1000</FCOUNT>
</SESSION>
ENVIROMENT
AS3
Ruby 186-25
PROBLEM
Coding errors "coercion of value"
© Stack Overflow or respective owner