13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with the file system<br />

var fileRef:FileRefer<strong>en</strong>ce = new FileRefer<strong>en</strong>ce();<br />

fileRef.addEv<strong>en</strong>tList<strong>en</strong>er(Ev<strong>en</strong>t.SELECT, selectHandler);<br />

fileRef.addEv<strong>en</strong>tList<strong>en</strong>er(Ev<strong>en</strong>t.COMPLETE, completeHandler);<br />

try<br />

{<br />

var success:Boolean = fileRef.browse();<br />

}<br />

catch (error:Error)<br />

{<br />

trace("Unable to browse for files.");<br />

}<br />

function selectHandler(ev<strong>en</strong>t:Ev<strong>en</strong>t):void<br />

{<br />

var request:URLRequest = new URLRequest("http://www.[yourdomain].com/fileUploadScript.cfm")<br />

try<br />

{<br />

fileRef.upload(request);<br />

}<br />

catch (error:Error)<br />

{<br />

trace("Unable to upload file.");<br />

}<br />

}<br />

function completeHandler(ev<strong>en</strong>t:Ev<strong>en</strong>t):void<br />

{<br />

trace("uploaded");<br />

}<br />

You can s<strong>en</strong>d data to the server with the FileRefer<strong>en</strong>ce.upload() method by using the URLRequest.method and<br />

URLRequest.data properties to s<strong>en</strong>d variables using the POST or GET methods.<br />

Wh<strong>en</strong> you attempt to upload a file using the FileRefer<strong>en</strong>ce.upload() method, the following ev<strong>en</strong>ts are dispatched:<br />

op<strong>en</strong> ev<strong>en</strong>t (Ev<strong>en</strong>t.OPEN): Dispatched wh<strong>en</strong> the upload operation starts.<br />

progress ev<strong>en</strong>t (ProgressEv<strong>en</strong>t.PROGRESS): Dispatched periodically as bytes of data from the file are uploaded.<br />

complete ev<strong>en</strong>t (Ev<strong>en</strong>t.COMPLETE): Dispatched wh<strong>en</strong> the upload operation completes successfully.<br />

httpStatus ev<strong>en</strong>t (HTTPStatusEv<strong>en</strong>t.HTTP_STATUS): Dispatched wh<strong>en</strong> the upload process fails because of an<br />

HTTP error.<br />

httpResponseStatus ev<strong>en</strong>t (HTTPStatusEv<strong>en</strong>t.HTTP_RESPONSE_STATUS): Dispatched if a call to the upload()<br />

or uploadUn<strong>en</strong>coded() method attempts to access data over HTTP and Adobe AIR is able to detect and return the<br />

status code for the request.<br />

securityError ev<strong>en</strong>t (SecurityErrorEv<strong>en</strong>t.SECURITY_ERROR): Dispatched wh<strong>en</strong> an upload operation fails<br />

because of a security violation.<br />

uploadCompleteData ev<strong>en</strong>t (DataEv<strong>en</strong>t.UPLOAD_COMPLETE_DATA): Dispatched after data is received from the<br />

server after a successful upload.<br />

ioError ev<strong>en</strong>t (IOErrorEv<strong>en</strong>t.IO_ERROR): Dispatched if the upload process fails for any of the following reasons:<br />

An input/output error occurred while Flash Player is reading, writing, or transmitting the file.<br />

The SWF tried to upload a file to a server that requires auth<strong>en</strong>tication (such as a user name and password).<br />

During upload, Flash Player does not provide a means for users to <strong>en</strong>ter passwords.<br />

The url parameter contains an invalid protocol. The FileRefer<strong>en</strong>ce.upload() method must use either<br />

HTTP or HTTPS.<br />

Last updated 6/6/2012<br />

659

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!