开发者

swf listens to XML, AS3

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?

ANSWER

I'm confused with setting up the variables, and there values. There's nothing wrong with the document, "I'm just stuck." I plan to do a lot of reading after all this research.

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

alt text http://www.ashcraftband.com/myspace/videodnd/soc.jpg


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);

            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);

//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.COU开发者_开发问答NT.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>

alt text http://www.ashcraftband.com/myspace/videodnd/soc_.jpg

Here's a link

http://videodnd.weebly.com/

If you're interested, you can install Ruby 186-25.

a. Install Ruby

b. Run policyserver.rb first

c. flashserver next.rb

d. CTRL_ENTER socketServer.fla

PROBLEM

Coding errors "coercion of value"


I'm not sure, but I noticed the use of int(...) above.

"Coercion of Value" generally means that you're trying to cast (or "change") the datatype from one type to an incompatible type. (say, change a string into a Boolean)

Your data is coming in to Flash as XML and you are converting some of it into "int". (Flash calls the "int" data type "Number". But that is not the problem based on your error.)

It has to do with the "XML to Number" conversion that you're attempting.


i prefer to extract xml data like this:

  private function onConfigLoaded(e:Event):void {
        var xml:XML = new XML(urlo.data);
        userData = new XMLList(xml.user);
        settings = new XMLList(xml);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜