Quantcast AS3 FileReference Example | The Danosphere.

The Danosphere.

Avatar

class TheDanosphere extends Dan implements Blog

AS3 FileReference Example

AS3 FileReference Pic

A while ago I made a post about FileReference in AS2. For a recent project I needed to create a simple uploader class which uploads files to a given server from flash, so once again I was face to face with FileReference, but this time in AS3. The syntax is almost identical, with a few small nuances. Ill let you download the source** to get the full details.

This example has some a few small frills, my favorite of which is the constructor takes a directory name where you would like the file to be uploaded (relative to the upload script), this allows me to reuse this class for many different uploads, to different directories.

** Note: For this to work you need to put “upload.php” on your server and point the variable ‘phpUploadScript’ in FileUploader.as on line 20 to upload.php.

Share this post with friends:
  • Twitter
  • Facebook
  • LinkedIn
  • email
  • del.icio.us
  • Digg
  • Reddit
  • Google Bookmarks
  • Mixx
  • StumbleUpon
  • Tumblr

Related Posts

  • http://mothteeth.com Lee

    The .as looks good but the .fla is corrupt or something. You might want to provide a new archive.

    -Lee

  • http://www.thedanosphere.com Dan

    Hey sorry guys I had the fla set to build to an absolute path instead of relative so you might have gotten a “Failed to build swf error”. Should be fixed now.

  • http://www.mothteeth.com Lee

    Thanks for that. Should be useful. For some reason this seems to cause problems for a lot of people, including myself.

    Just thought I’d mention, for anyone who is confused, to make this code work you have to edit the phpUploadScript value in the FileUploader.as class file, and also set the upload folder in line 8 of the fla:

    var up:FileUploader = new FileUploader(“dynamicDir”);

    (ie dynamicDir needs to be “uploads” for example.)

    Thanks again.

  • Newen

    Hi. i’m using this. it’s very pretty nd all. looks like everythings perfect but the actual upload is not working. i don’t know why. i checked the url, the upload dir, the folders permissions.

    The tracings confirming the upload. but no actual file is being uploaded.

    any ideas?

  • Newen

    ok… i did another test. when i didn’t put any directory in line 8 of the file.
    var up:FileUploader = new FileUploader();

    it doesn’t work. but as soon as i put “uploads” in there it works fine.

    Thanks for a great component.

  • blank

    thanks a lot for a great component indeed. this will be really useful to me as a learning exercise.

  • mike

    So how do you get this to work using two buttons? One for Browse, and the other for Upload?

  • http://www.thedanosphere.com Dan

    @mike:

    To get it to work using 2 seperate buttons you will just need to create a “Browse” button and use the FileUploader.browse() to handle the MOUSE_UP event.

    Then just comment out line 37 in FileUploader.as and make the selectFile(e:Event) function public scope. Have your “Upload” button use that function as a handler. That should give you the desired effect.

    Right selecting a file automatically triggers the upload… so the key is really just removing the this._fileRef.addEventListener(Event.SELECT, this.selectFile); line [37] of code and having your “Upload” button use the selectFile function as a handler instead.

    Hope that helps!

  • patrick

    Can someone help me. When I upload with a html form it works. Using this flash example I get an error:

    Error #2038

  • patrick

    Found solution @ flashkite

    just write this two lines in the .htaccess file at the root folder

    SECFILTERENGINE OFF
    SECFILTERSCANPOST OFF

  • joe

    i want to be able to ‘browse’ again if the user clicks ‘close’ to cancel the file dialog. is this possible?

  • http://onet.pl ok

    good site pofthc

  • Elaine

    Please help…
    I followed exactly..
    but still cannot upload.
    it says upload succesful but no file is uploaded…

  • Elaine

    yeay yeay
    I finally got it working
    is the server folder setting.
    Thank you for this simple direct useful code…Love it..
    you save my life..
    Thanks

  • sam

    grrr this is frustrating i have the same problem as theperson above had but i cant work out how to make it work! it never uploads a file… where is te upload directory on my server or in my local folder? i am just running on my computerand its linking to the php on the server is this a problem??

  • http://i-create.org/2009/01/19/papervision3d-3d-picasa/ i-create | therefore-i am » Blog Archive » Papervision3D 3D Picasa

    [...] to point out is because I used picasa not only did I have to parse out the MediaRSS but I had to use flash file reference to check when the images are loaded.  Another tricky gotcha I found was the fact that Picasa will [...]

  • http://dusellfam.com BA5IK.57

    This is pertty nice class Thanks for sharing ~ Wes

  • Rachael

    Thanks for this! My files are uploading perfectly but I want to display the uploaded image on the screen.

    does anyone know how I could do this? Is the file name held anywhere so I can access it?

    thanks

    Rachael

  • woody35

    Using your example, I got the error: “the variable ComponentShim is not defined”`
    Do you have any idea where this error comes from?

  • woody35

    Using your example, I got the error: “the variable ComponentShim is not defined”`
    Do you have any idea where this error comes from?

    Thanks
    Boris

  • john

    1046: Type was not found or was not a compile-time constant: UploadCompleteEvent.
    function handleSuccess(e:UploadCompleteEvent):void {

    1046: Type was not found or was not a compile-time constant: UploadCompleteEvent.
    function handleFail(e:UploadFailedEvent):void {

  • john

    1046: Type was not found or was not a compile-time constant: UploadCompleteEvent.
    function handleSuccess(e:UploadCompleteEvent):void {

    1046: Type was not found or was not a compile-time constant: UploadCompleteEvent.
    function handleFail(e:UploadFailedEvent):void {

  • john

    1046: Type was not found or was not a compile-time constant: UploadCompleteEvent.
    function handleSuccess(e:UploadCompleteEvent):void {

    1046: Type was not found or was not a compile-time constant: UploadCompleteEvent.
    function handleFail(e:UploadFailedEvent):void {

  • Balajisanala

    Thank you very much, useful one.

  • Alex

    Thanks a lot. Great post!!

blog comments powered by Disqus

What's Here?