我试过这个,但它不起作用:
package{
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.MovieClip;
import flash.events.Event;
public class ReadFile extends MovieClip {
var urlLDR:URLLoader;
var urlR:URLRequest;
public function ReadFile ():void
{ init();}
public function init ():void {
urlLDR = new URLLoader();
urlR = new URLRequest("ftpserver.xls");
//urlR = new URLRequest("Test.xls");
urlLDR.load(urlR);
urlLDR.addEventListener(Event.COMPLETE,f);
}
function f(e:Event){
trace(e.target.data);
}
}//class
}//package
如果您有任何想法,那就来......
答案 0 :(得分:3)
你的问题是什么?你有任何错误吗?尝试添加更多侦听器以排除问题。
package {
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;
public class URLLoaderExample extends Sprite {
public function URLLoaderExample() {
var loader:URLLoader = new URLLoader();
configureListeners(loader);
var request:URLRequest = new URLRequest("urlLoaderExample.txt");
try {
loader.load(request);
} catch (error:Error) {
trace("Unable to load requested document.");
}
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
private function completeHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
trace("completeHandler: " + loader.data);
var vars:URLVariables = new URLVariables(loader.data);
trace("The answer is " + vars.answer);
}
private function openHandler(event:Event):void {
trace("openHandler: " + event);
}
private function progressHandler(event:ProgressEvent):void {
trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function httpStatusHandler(event:HTTPStatusEvent):void {
trace("httpStatusHandler: " + event);
}
private function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
}
}
答案 1 :(得分:1)