问题描述
我只有这么多分数了,全部给了,还请高手帮忙看一下。在下先谢过了编译生成swf文件后单独能运行,并且能和服务器telnet,一切正常,但是当我把这个方腊时嵌入到html网页当中是,就不能运行了。我找了很久也没有找到原因,请大家帮忙看一下问题的所在。一下是源文件(TelnetSocket.mxml和Telnet.as)1.TelnetSocket.mxml<?xmlversion="1.0"encoding="utf-8"?><mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"layout="vertical"><mx:Script><![CDATA[importcom.example.programmingas3.socket.Telnet;privatevartelnetClient:Telnet;privatefunctionconnect():void{telnetClient=newTelnet(serverName.text,int(portNumber.text),output);console.title="Connectingto"+serverName.text+":"+portNumber.text;console.enabled=true;}privatefunctionsendCommand():void{varba:ByteArray=newByteArray();ba.writeMultiByte(command.text+"n","UTF-8");telnetClient.writeBytesToSocket(ba);command.text="";}]]></mx:Script><mx:Labelid="title"text="TelnetSocketExample"fontSize="24"fontStyle="bold"/><mx:Labelid="subtitle"text="FromProgrammingActionScript3.0,Chapter22:Networkingandcommunication"fontSize="12"/><mx:ApplicationControlBarwidth="100%"><mx:Labeltext="Server:"/><mx:TextInputid="serverName"text="192.168.0.150"width="100%"/><mx:Spacer/><mx:Labeltext="Port:"/><mx:TextInputid="portNumber"text="503"textAlign="right"maxChars="5"restrict="0-9"/><mx:Spacer/><mx:Buttonlabel="Login"click="connect();"/></mx:ApplicationControlBar><mx:Spacer/><mx:Panelid="console"enabled="false"width="100%"height="100%"paddingTop="10"paddingBottom="10"paddingLeft="10"paddingRight="10"><mx:TextAreaid="output"editable="false"width="100%"height="100%"fontFamily="CourierNew"/><mx:ControlBar><mx:Labeltext="Command:"/><mx:TextInputid="command"width="100%"enter="sendCommand();"/><mx:Buttonlabel="Send"click="sendCommand();"/></mx:ControlBar></mx:Panel></mx:Application>2.Telnet.aspackagecom.example.programmingas3.socket{importflash.events.*;importflash.net.Socket;importflash.system.Security;importflash.utils.ByteArray;importflash.utils.setTimeout;importmx.controls.TextArea;importmx.core.UIComponent;publicclassTelnetextendsUIComponent{privateconstCR:int=13;//CarriageReturn(CR)privateconstWILL:int=0xFB;//251-WILL(optioncode)privateconstWONT:int=0xFC;//252-WON'T(optioncode)privateconstDO:int=0xFD;//253-DO(optioncode)privateconstDONT:int=0xFE;//254-DON'T(optioncode)privateconstIAC:int=0xFF;//255-InterpretasCommand(IAC)privatevarserverURL:String;privatevarportNumber:int;privatevarsocket:Socket;privatevarta:TextArea;privatevarstate:int=0;publicfunctionTelnet(server:String,port:int,output:TextArea){//setclassvariablestothevaluespassedtotheconstructor.serverURL=server;portNumber=port;ta=output;//CreateanewSocketobjectandassigneventlisteners.socket=newSocket();socket.addEventListener(Event.CONNECT,connectHandler);socket.addEventListener(Event.CLOSE,closeHandler);socket.addEventListener(ErrorEvent.ERROR,errorHandler);socket.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);socket.addEventListener(ProgressEvent.SOCKET_DATA,dataHandler);//Loadpolicyfilefromremoteserver.Security.loadPolicyFile("http://"+serverURL+"/crossdomain.xml");//Attempttoconnecttoremotesocketserver.try{msg("Tryingtoconnectto"+serverURL+":"+portNumber+"n");socket.connect(serverURL,portNumber);}catch(error:Error){/*Unabletoconnecttoremoteserver,displayerrormessageandcloseconnection.*/msg(error.message+"n");socket.close();}}/***ThismethodiscalledifthesocketencountersanioErrorevent.*/publicfunctionioErrorHandler(event:IOErrorEvent):void{msg("Unabletoconnect:socketerror.n");}/***Thismethodiscalledbyourapplicationandisusedtosenddata*totheserver.*/publicfunctionwriteBytesToSocket(ba:ByteArray):void{socket.writeBytes(ba);socket.flush();}privatefunctionconnectHandler(event:Event):void{if(socket.connected){msg("connected...n");}else{msg("unabletoconnectn");}}/***Thismethodiscalledwhenthesocketconnectionisclosedby*theserver.*/privatefunctioncloseHandler(event:Event):void{msg("closed...n");}/***Thismethodiscalledifthesocketthrowsanerror.*/privatefunctionerrorHandler(event:ErrorEvent):void{msg(event.text+"n");}/***Thismethodiscalledwhenthesocketreceivesdatafromtheserver.*/privatefunctiondataHandler(event:ProgressEvent):void{varn:int=socket.bytesAvailable;//Loopthrougheachavailablebytereturnedfromthesocketconnection.while(--n>=0){//Readnextavailablebyte.varb:int=socket.readUnsignedByte();switch(state){case0://Ifthecurrentbyteisthe"InterpretasCommand"code,setthestateto1.if(b==IAC){state=1;//Else,ifthebyteisnotacarriagereturn,displaythecharacterusingthemsg()method.}elseif(b!=CR){msg(String.fromCharCode(b));}break;case1://Ifthecurrentbyteisthe"DO"code,setthestateto2.if(b==DO){state=2;}else{state=0;}break;//Blindlyrejecttheoption.case2:/*Writethe"InterpretasCommand"code,"WONT"code,andcurrentbytetothesocketandsendthecontentstotheserverbycallingtheflush()method.*/socket.writeByte(IAC);socket.writeByte(WONT);socket.writeByte(b);socket.flush();state=0;break;}}}/***AppendmessagetotheTextAreacomponentonthedisplaylist.*Afterappendingtext,callthesetScroll()methodwhichcontrols*thescrollingoftheTextArea.*/privatefunctionmsg(value:String):void{ta.text+=value;ta.dispatchEvent(newEvent(Event.CHANGE));setTimeout(setScroll,100);}/***ScrolltheTextAreacomponenttoitsmaximumverticalscroll*positionsothattheTextAreaalwaysshowsthelastlinereturned*fromtheserver.*/publicfunctionsetScroll():void{ta.verticalScrollPosition=ta.maxVerticalScrollPosition;}}}
解决方案
解决方案二:
该回复于2011-04-11 09:46:01被版主删除
解决方案三:
额。flex的。。搞过。没嵌过。不好意思哈
解决方案四:
拜托帮帮忙
解决方案五:
拜托,帮帮忙
解决方案六:
权限不一样的,你本地运行swf是本地沙箱,你嵌入到html里是远程沙箱,因为连接的远程服务器没有策略文件,所以你无法访问,详见http://help.adobe.com/zh_CN/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e08.html
解决方案七:
我也是这毛病,加了策略文件了也不行呢。不知是为什么。
解决方案八:
varg_nTotalRecvByte=0;varg_time=newDate();varg_nStartTime=g_time.getTime();varg_nCounter=0;varnum_table=newArray("0","1","2","3","4","5","6","7","8","9");varmySocket=newXMLSocket();//安全沙箱,没有的话,有安全问题,就不能跨域访问数据了。System.security.sandboxType=localTrusted;System.security.loadPolicyFile("xmlsocket://xym5366.vicp.net:6000");System.security.loadPolicyFile("xmlsocket://xym5366.vicp.net/flashpolicy.xml:6000");_root.mySocket.connect("xym5366.vicp.net",6000);//Á¬½ӷþÎñÆ÷_root.mySocket.onConnect=function(success){if(success){_root.txt.text="连网成功";trace("连网成功");}else{_root.txt.text="安全沙箱没有通过,连网失败。如果您有好的办法,请emil我,谢谢。";trace("连网失败");}}functionConvertToMsg(str){varl=str.length+3;vart="";if(l>=10)t=num_table[Math.floor(l/10)]+num_table[Number(l%10)]+str;elset=num_table[0]+num_table[l]+str;returnt;}mySocket.onData=function(xmlDoc){txt.text=xmlDoc;trace(xmlDoc);}//下面是按钮的代码on(press){varmsg=_root.ConvertToMsg(_root.tsk.text);trace(msg);_root.mySocket.send(msg);}
解决方案九:
我这些代码也不行,我是flash8,用的是自建的花生壳iis,根目录也放策略文件了,就是不行。引用7楼xym5366的回复:
varg_nTotalRecvByte=0;varg_time=newDate();varg_nStartTime=g_time.getTime();varg_nCounter=0;varnum_table=newArray("0","1","2","3","4","5","6","7","8","9");varmySocket=new……