AS3/Flash, How to make a button to browse and load dynamic text files within this code?
This is a script that loads the specified .log (text) file and shows its content dynamically in the movie (artist and song from the current track played).
Because the player makes new .log files after a certain time, I need to select the latest .log file manually when starting the .swf or when it changes during the session. What I am doing, is opening the trackLogNum.txt file and writing there the 5 NUMBER section (logNum variable) of the .log filename structure, which is, i.e. 127.0.0.1,12345.log
Is there any way to implement a button in this code to browse the .log files in the directory and then select and load the latest one, instead of writing each time the filename in the external trackLogNum.txt?
I think it would be perfect a function that loads automatically the newest .log file (as I see in dynamically loading of pictures within slideshows, which frequently have breadcrumb buttons to go to the first and also the last item), but they said it is not possible without using PHP or Flex. As you notice in t开发者_运维知识库he code, it is a local application, no server is running.
Thank you in advance for your help.
var reload:Timer = new Timer(5000, 1);
reload.addEventListener(TimerEvent.TIMER, onTimer);
//--------------------
var logNumLoader:URLLoader = new URLLoader();
logNumLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
logNumLoader.addEventListener(Event.COMPLETE, loadedLogNum);
logNumLoader.load(new URLRequest("trackLogNum.txt"));
var _logNum:String;
function loadedLogNum(e:Event):void {
trace(e.target.data.logNum);
_logNum = e.target.data.logNum;
loadTracks();
}
//--------------------
var tracksLoader:URLLoader = new URLLoader();
tracksLoader.addEventListener(Event.COMPLETE,onTracksLoaded);
tracksLoader.addEventListener(IOErrorEvent.IO_ERROR,onTracksError);
tracksLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onTracksError);
loadTracks();
function onTracksLoaded(e:Event):void {
trace("onTracksLoaded");
parseTracks(tracksLoader.data);
reload.start();
}
function onTimer(event:TimerEvent):void{
loadTracks();
}
function onTracksError(e:Event):void {
trace("onTracksError", e);
reload.start();
}
function loadTracks():void {
tracksLoader.load(new URLRequest("127.0.0.1,"+_logNum+".log"));
}
function parseTracks(data:String):void {
try {
var lines:Array = data.split("\n");
var lastLine:String = lines[lines.length - 2];
var artistAndSong:String = lastLine.substr(24).split(" - ").join("\n\n->");
trace(artistAndSong);
track_info.text = artistAndSong;
addChild(track_info);
} catch(e:Error) {
}
}
There exists a flash.filesystem available for Actionscript 3.0 that offers some interesting classes to browser a directory. Sadly and for security reasons mainly, it is only available when compiling your project against AIR. Have you considered creating an AIR application instead of a normal swf?
In order to use the filesystem package (and be able to browser your log files) you will need to convert your application to an AIR application. You can do this by changing the publication settings:
I found a good example on how to browser all files on the desktop.
精彩评论