学习字符串参数,Flash AS3

时间:2010-02-22 23:12:55

标签: flash actionscript-3 string

我对字符串很糟糕,可能搞砸了。我的Flash文件接收XML命令并更改动画的值(速度,时间)。你能改进这个字符串参数,或者让我知道我需要做些什么不同的事情。

XML

    <head>
    </head>
    <body>
    <cnt>1count*count/10</cnt>
    </body>

是对的吗?

                    //XML ==> STRING   
var string_tangle:String = xml_msg.body.cnt; //LINE 27

                    //STRING ==> url request    
var urlReq:URLRequest = new URLRequest(string_tangle); //LINE 28

                    //VALUE ==>       
fcount=int(urlReq);<br> //GOES TO LINE 49 "urlReq instead of (1count*count/10)"

myloader.swf

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

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

//MY SOCKET
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 string_tangle:String = xml_msg.body.cnt;
            var urlReq:URLRequest = new URLRequest(string_tangle);
            //fcount=int(urlReq);
            break;
        case 'close':
            trace("Connection Closed!"); //OnDisconnect :( //
            xml_s.close();
            break;
    }
}
//////////////////////////////////////////////////////////////
//MY 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; 

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

function incrementCounter(event:TimerEvent) {  
  count++; 
  //WANT TO CHANGE THIS IN LINE 50//fcount=int(urlReq);
  fcount=int(count*count/1000);
  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); 
}

错误“可能已经破坏了一些东西。在重写之前它运作良好。
安全沙箱违规
错误#2031:套接字错误

1 个答案:

答案 0 :(得分:0)

很可能违反了Adobe安全政策。

尝试更改Flash播放器中的安全设置,或点按此链接进行操作: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html