dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Screen does not refresh on XML Socket -Help Would be great

  1. #1
    Junior Member
    Join Date
    Jan 2001
    Posts
    3
    I would really appreciate any help with this. I'm trying to have Cold Fusion send an XML message to a Java socket server which sends it to a flash client over an XML socket. So far I can get Flash to parse through the XML and print the results out to a a textfield called console2 (Although I am having a bit of a problem constructing the actual hyperlink, but that's a side issue). The problem is that when I invoke the exact same page (That sends the XML message) a second or third time around Flash will not display the results again on the console2 textfield. I have no idea why this is happening.
    Here's what I've tried:
    I as you can see with the code I am attempting to clear the console2 textfield every time new XML data comes in. I've tried destroying the console object and then recreating it, but that didn't work. I also tried destrying and recreating the tarray that hold the child nodes, but that didn't work either. Any help would be greatly appreciated.
    Ilusion


    socket = new XMLSocket();
    socket.onXML = newXML;
    socket.onConnect = newConnection;
    socket.connect("localhost", 9999);


    function newXML(data){

    console2 = "";

    tarray = new Array();
    tarray = data.firstChild.childNodes;


    for ( i=0;i<tarray.length;i++ ) {


    PageTitle = tarray.attributes.PageTitle;

    console2 += "<A HREF='edit.cfm?editor\=true&Pagetitle\="+PageTitle +"'>"+PageTitle+"</A>"+newline;

    }


    }

    function newConnection(good){
    if (good){
    console += "Connected"+newline;
    }else{
    console += "Could not Connect!"+newline;
    }
    }


    stop ();

  2. #2
    Moderator
    Join Date
    Aug 2000
    Posts
    1,455
    Hmm...

    The AS XML code looks fine to me. I suggest that you check the CF code and the Java Socket Server code to make sure that it's not trying to be too clever or anything!

    If that's all fine then maybe Aria or FlashGuru can spot something that I can't!

    I hope this helps!

    Regards,

    Steve

  3. #3
    Junior Member
    Join Date
    Jan 2001
    Posts
    3

    Smile Fixed it, if it helps anyone here's the answer.

    Well, I was going across some old versions of my app and I came across one where I put in someone else's function (CleanTree) to clean up the XML. For some reason, this fixes the problem of the XML appearing the second time around. I have no idea why.

    Ilusion

    CODE:

    socket = new XMLSocket();
    socket.onXML = newXML;
    socket.onConnect = newConnection;
    socket.onClose = handleClose;
    socket.connect("localhost", 9999);


    function newXML(data){
    cleanTree(data);

    console2 = "";

    tarray = new Array();
    tarray = data.firstChild.childNodes;


    for ( i=0;i<tarray.length;i++ ) {


    PageTitle = tarray.attributes.PageTitle;

    console2 += "<A HREF='edit.cfm?editor\=true&Pagetitle\="+PageTitle +"'>"+PageTitle+"</A>"+newline;

    }


    }

    function newConnection(good){
    if (good){
    console += "Connected"+newline + "------------------------------------------" +newline;
    }else{
    console += "Error Connecting!"+newline;
    }
    }


    function handleClose () {
    console += ("the server at "+socket.host+" has terminated the connection.\n");

    socket.connected = false;

    }

    function cleanTree(XMLObject) {
    var children;
    var child;
    var i;

    children = XMLObject.childNodes;

    for (i=0; i<children.length; i++) {
    child = children;

    if (child.nodeType == 3) {
    if (child.nodeValue == null) {
    child.removeNode();
    }
    else {
    child.nodeValue = trim(child.nodeValue);
    if (child.nodeValue.length == 0) {
    child.removeNode();
    i--; //subtract 1 from the index variable, since removing a node re-arranges the array of childNodes.
    }
    }
    }
    else {
    cleanTree(child);
    }

    }
    }

    function trimLeft(string) {
    if (string.length == 0) {
    return string;
    }

    var pos = 0;
    while (string.charCodeAt(pos) <= 32){
    pos++;
    if (pos == string.length) {
    break;
    }
    }
    return string.substr(pos,string.length - pos);
    }

    function trimRight(string) {
    if (string.length == 0) {
    return string;
    }

    var pos = string.length - 1;
    while (string.charCodeAt(pos) <= 32){
    pos--;
    if (pos < 0) {
    break;
    }
    }
    return string.substring(0, pos + 1);
    }

    function trim(string) {
    return trimLeft(trimRight(string));
    }


    stop ();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center