完成参数“起始码”AS3

时间:2010-02-25 18:45:12

标签: flash actionscript-3

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

如何完成控制外部swf的参数?粗略的“入门代码”示例如何编写它将会有所帮助。

问题
我不能遵循字符串参数和“钻进来”外部文档。我正在追赶。

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 需要接收数据()

//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消息

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

结果
即使让一种方法像“fcount”一样工作也会给 我理解。 XML很简单,但这个项目很难 测试并由TCP / IP套接字连接控制。这些是实施在线游戏或信息亭的常见问题。

1 个答案:

答案 0 :(得分:0)

这是一个简单的套接字示例:

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

这是关于flash中套接字的教程:http://www.ultrashock.com/forums/tutorials/actionscript-3-socket-communication-81676.html