开发者

finish argument “starter code” AS3

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

How do I finish arguments to control an external swf? A sketchy “starter code” example of how to write this would be helpful.

problem

I can’t follow the string arguments and “drilling-in-to” external documents. I'm playing catch up.

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

loader.swf

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

external.swf NEEDS TO RECEIVE DATA ()

//Tick Tock
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;

timer.addEventListener(TimerEvent.TIMER, incrementCounter); 
timer.start(); 

function incrementCounter(event:TimerEvent) { 
  count++; 
  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);
}

xml message

/*"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>

Result

Even getting one method to work like “fcount” would give me an understanding. XML is easy, but this project is hard to test and is control by a TCP/IP socket connection. These are probaly common hurtles to implementing an online game or kiosk.


Here is a simple socket example:

var xml_s=new XMLSocket();
xml_s.connect(ip,port);
xml_s.addEventListener(Event.CONNECT,xmlsocket);//OnConnect//
xml_s.addEventListener(Event.CLOSE,xm lsocket);//OnDisconnect//
xml_s.addEventListener(IOErrorEvent.I O_ERROR,xmlsocket);//Unable To Connect//

public function xmlsocket(Event):void{
switch(Event.type){
case 'ioError':
//Unable to Connect :(//
break;
case 'connect':
//Connected :)//
break;
case 'close':
//OnDisconnect :( //
break;
}
}

xml_s.send("MESSAGE HERE");

Here is a tutorial on sockets in flash: http://www.ultrashock.com/forums/tutorials/actionscript-3-socket-communication-81676.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜