這是我涉及閃存外部類的第一個項目,所以這可能是一個相當基本的問題: 我試圖加載的類CSVloader csv文件:AS3無法加載一個CSV文件
package Application {
import flash.events.Event;
import flash.display.Loader;
import flash.filesystem.File;
import flash.net.*;
import Application.*;
public class CSVloader {
private var waiting = true;
private var CSVdata:Array;
private var myCsvLoader:URLLoader = new URLLoader;
public function CSVloader() {
}
public function loadCSV(Args:String){
myCsvLoader.dataFormat = URLLoaderDataFormat.TEXT;
myCsvLoader.load(new URLRequest(Args));
myCsvLoader.addEventListener(Event.COMPLETE, onWait);
return CSVdata;
}
public function onCSVLoaderReady():Array {
var CSVdata:Array;
var str:String = myCsvLoader.data as String;
CSVdata = str.split("\n");
for (var i:int=0; i<CSVdata.length; i++) {
CSVdata[i] = CSVdata[i].split(';');
}
for(var q:int = 0; q<(CSVdata.length-1);q++){
CSVdata[q][1] = CSVdata[q][1].slice(0,-1);
}
trace("CSV loaded! : " + CSVdata);
return CSVdata;
}
private function onWait(e:Event):void{
CSVdata = onCSVLoaderReady();
}
}
}
我怎樣才能寫CSVloader類,所以當我調用CSVloader(「一些網址」)我得到一個數組與所有的數據?
這是我的AppController類:
package{
import Application.CSVloader;
import Application.C;
import flash.display.MovieClip;
public class AppController extends MovieClip{
public function AppController() {
// constructor code
}
public function init(){
var myCSVLoader = new CSVloader();
trace(myCSVLoader.loadCSV("data.csv"));
}
}
}