开发者

How can Flash AS3.0 Read file text while text file still writing by C++ program?

How can Flash AS3.0 Read file text while text file still writing by C++ program ?

I have some code that I asked before + I modify some line but It can read only text file that completely writing.

import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;

var toLoad:URLRequest = new URLRequest("example.txt");
var loader:URLLoader = new URLLoader(toLoad);
loader.addEventListener(Event.COMPLETE, loaded, false, 0, true);

function loaded(evt:Event):void
{
    var txtData:String = evt.currentTarget.data;
    txtData = txtData.replace(/^\s+/, '');
    txtData = txtData.replace(/\s+/g, ' ');
    txtData = txtData.repl开发者_如何学编程ace(/\s+$/, '')
    var textAr:Array = txtData.split(" ");
 var xArray:Array = new Array;
 var yArray:Array = new Array;
 var i=0;
 var ii = textAr.length;
 while (i < ii)
 { 
  if (textAr[i] != "---")
  {
   xArray.push(textAr[i]);
   yArray.push(textAr[i+1]);
   i+=2;
  }
  else 
  {
   xArray.push("-");
   yArray.push("-");
   i++;
  }
 }
}

Now My task is read real time file and send xArray and yArray to another function but I don't know how can I code it.

please,Help me.


I'm not sure how the C++ program is writing your file, but I suppose it's nothing fancy, it just opens the file, writes the content and closes it. The thing is that the content isn't saved on disk until C++ closes the file (and thus saves it).

So, to solve your problem, you should modify the C++ program (if you can), to write small parts of the content to the file, then close it and open it again. Same thing with your flash program. It won't be realtime, but it would be close enough.

Anyway, a text file isn't the best choice for real time reading. You could use sockets or something else for communication between C++ and Flash.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜