tags:

views:

42

answers:

0

I want to control the time of a counter. I need to receive XML data from a TCP/IP socket controlling the values of my counter.

Flash client 'LOADER' receives XML messages and loads swf files. How do I rewrite LOADER and LOADEDSWF to pass this type of event data? Correct my question if I'm wrong.

HOW I SEE IT "I'll see "Event.data" instead of number values

1. LOADER "parse XML==>pass to own variables==>passed to LOADEDSWF
2. LOADEDSWF receives event data "it resets it's values"

VARIABLES I'M TRYING TO CONTROL
-timer
-count
-fcount
-incrementCounter "function"

LOADEDSWF.swf "needs setup for Event.data"

//Set millions counter
//Set values of timer
var timer:Timer = new Timer(10);  
var count:int = 0; //start at -1 if you want the first decimal to be 0  
var fcount:int = 0;//where it starts time ramp

timer.addEventListener(TimerEvent.TIMER, incrementCounter);  
timer.start();  
//Set incrementCounter 
function incrementCounter(event:TimerEvent) {  
  count++; 
  //Set values of fcount
  fcount=int(count*count/1000);//starts out slow... then speeds up 
  mytext.text = formatCount(fcount);
}

function formatCount(i:int):String { 
     var fraction:int = i % 100; 
     var whole:int = i / 100;  

    return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" + fraction : fraction); 
} 

LOADER.swf "needs setup for Event.data"

import flash.net.*;
import flash.display.Loader;
import flash.events.*;
import flash.system.Security;

//Security.loadPolicyFile("xmlsocket://192.168.0.198:843"); 
//Security.showSettings();

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 xml_msg:XML = new XML(Event.data);
            var file_to_load:String = xml_msg.body.file;
            var urlReq:URLRequest = new URLRequest(file_to_load);
            var myMovie = null;
            var ldr:Loader = new Loader();
            //ldr.contentLoaderInfo.addEventListener(Event.complete, onComplete);
            ldr.load(urlReq);
            trace("loader.content: " + ldr.content);
            if (myMovie != null)
                bg.removeChild(myMovie);


            //ldr.content.stage.height = 300;
            //ldr.stage.width = 500
            myMovie = bg.addChild(ldr);
            /*
            var ldr:Loader = new Loader();
            var urlReq:URLRequest = new URLRequest(Event.data);
            ldr.load(urlReq);
            */
            break;
        case 'close':
            trace("Connection Closed!"); //OnDisconnect :( //
            xml_s.close();
            break;
    }
}

XML"basic example"

/*"XML"*/
<head>

<seq_no>text</seq_no> 
</head>

<body>

/*"WHERE IT STARTS"*/ 
<count_int>0</count_int>

/*"TIMESCALE"*/ 
<timer>10</timer>

/*"TIME CURVE"*/
<fcount_>0</fcount_>

/*function time settings*/
<incrementCounter_>count*count/1000</incrementCounter_>

/*"FILE TO LOAD"*/
<file>1.swf</file>

</body>