PDA

View Full Version : error in upload code


ninjapeps
04-24-2009, 04:13 AM
Just wondering what's wrong with my code. I keep getting this error whenever I run it:

Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File I/O Error.
at makefile_fla::MainTimeline/frame1()

Anyway, here's the code I used. Thanks.

import flash.filesystem.*;

var file:File = File.documentsDirectory;
file = file.resolvePath("test.txt");
var fileStream:FileStream = new FileStream();
fileStream.openAsync(file, FileMode.WRITE);
fileStream.writeUTFBytes("Hello");
fileStream.addEventListener(Event.CLOSE, fileClosed);
fileStream.close();
function fileClosed(event:Event):void {
trace("closed");
}

var file_ref:FileReference = new FileReference();
file_ref.addEventListener(Event.SELECT, file_select);
file_ref.addEventListener(Event.COMPLETE, upload_complete);

function file_select(event:Event):void {
text_txt.text = "file selected: " + file_ref.name;
}

function upload_complete(event:Event):void {
text_txt.text = "upload successful";
}

button_btn.addEventListener(MouseEvent.CLICK, file_browse);

function file_browse(event:MouseEvent):void {
file_ref.browse();
}

upload_btn.addEventListener(MouseEvent.CLICK, file_upload);

function file_upload(event:MouseEvent):void {
var request:URLRequest = new URLRequest("http://localhost/");
file_ref.upload(request);
}

Oh yeah, there's only one frame in this movie with two buttons and a textfield.

<edit>
The target in the upload function should be a php file, shouldn't it?
</edit>

<edit>
Never mind. It's working now.
</edit>