-
problem loading txt file into array with AS3
Hello, I am using flash CS3 actionscript 3. basically i am working on a image rotator that grabs the images from a certain directory using php and displays them in a pretty fade in/out manner. that is done. now i am working on a simple video player that will continuously repeat videos that are listed in a txt file. the whole idea of this is so that once this is created, the flash files will not need to be re published, someone can just add videos to the directory and edit a text file, refresh, and the new videos will be replayed. this is what i have so far.
Code:
var counter:int = 0;
var playList:Array = ["1.flv","2.flv"];
PRPvids.source = playList[counter];
PRPvids.addEventListener(Event.COMPLETE, nextVid);
function nextVid(e:Event):void {
counter ++;
if (!playList[counter]) {
counter=0;
}
PRPvids.source = playList[counter];
}
i think i need the load the txt and split it into an array but ive tried for the last 2 days and i am coming to a halt. thanks for any replies!
-
PHP Code:
function oncomplete(event:Event):void{
var string:String = event.currentTarget.data;
var playList:Array = string.split("\r\n");
// do stuff to playList
};
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("some/text/file.ext");
loader.addEventListener("complete",oncomplete);
loader.load(request);
-
hey thanks for the input!
this is the final code ill be using for this. :-)
Code:
var myLoader:URLLoader = new URLLoader()
myLoader.dataFormat = URLLoaderDataFormat.TEXT
myLoader.load(new URLRequest("list.txt"))
myLoader.addEventListener(Event.COMPLETE, onLoader)
function onLoader(ev:Event){
trace ("Data loaded")
trace (myLoader.data)
var string:String = myLoader.data;
var counter:int = 0;
var playList:Array = string.split("\r\n");
PRPvids.source = playList[counter];
PRPvids.addEventListener(Event.COMPLETE, nextVid);
function nextVid(e:Event):void {
counter ++;
if (!playList[counter]) {
counter=0;
}
PRPvids.source = playList[counter];
}
}
-
-
just as a follow up to anyone who may use this as a guide in the future. where I split using "/r/n" it was having problems getting the correct data for the array when loading from the web server but worked perfect locally. So I change the split to "," and set up my text file something like this
Code:
video1.flv,video2.flv,video3.flv
and so on.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|