cash loans
24 October 2008

UPDATED: Using AS3 to Upload and Encode Images

After many requests, I’ve updated the demo and source files for the wildly popular labs post Using AS3 to Upload and Encode Images. Hope everyone finds it helpful.

posted by Shaun Tinney

thinking about… AS3, Experiments, Flash, Research

17 Comments…

  1. am said…

    hi!

    big thanks for the files. I’m migrating from as2 + leaving timeline and trying to get my head into oop. It was really great to see a project done this way, i’m studing it and trying to learn with it. Till now i found just one issue that i can’t find a answer, it’s about the ErrorEvent.ERROR, is this a event from flash?

    thanks again for all the share
    :)

    5:22 am / December 11th, 2008

  2. randygland said…

    Cool!

    many thanks for this.. .I wrote in the other post i was writing a flex ap which will use this method.. I’ll post the results asap.

    4:16 am / January 9th, 2009

  3. adrian p said…

    was wondering if someone could tell me how to export/record the whole stage
    The AS says
    private var m_capture : Sprite; // (set to stage)

    but changing this line ,Sprite to stage doesnt do anyhing

    thanks

    adrian

    5:24 pm / May 15th, 2009

  4. Shaun Tinney said…

    @adrian, you’d have to set the contents of the variable, not just the type. If you change the capture area where the bitmapData is drawn, that should do the trick. For example:

    // set up a new bitmapdata object that matches the dimensions of the stage;
    var bmd : BitmapData = new BitmapData( stage.stageWidth, stage.stageHeight, true, 0xFFFFFFFF );
    			
    // draw the bitmapData from the stage to the bitmapData object;
    bmd.draw( stage, new Matrix(), null, null, null, true );
    

    12:09 pm / May 20th, 2009

  5. christian said…

    hi great work but im kinda new to as3 so i hope you can help me out. I kinda miss the part where you encoded the uploaded image to a flash movie clip container. Im struggling to make this work since all i needed now is to upload an image to my flash project.

    Thanks

    11:55 pm / June 9th, 2009

  6. mw said…

    I’m very excited about using this…
    and I’ve got it working 99% …

    this but I am getting an Error #2176 …

    ( Error #2176 Certain actions, such as those that display a pop-up window, may only be invoked upon user interaction, for example by a mouse click or button press.)

    this error happens on pressing the create button.
    after selecting “continue” it lets me continue to upload / download images. So technically it works if it wasn’t for that annoying flash error window that I’ve seen more to my liking these days.

    any one know how I could solve this?
    thanks.

    5:30 pm / June 13th, 2009

  7. Dane said…

    I see the same error in the demo. (see below) looks like it works though. I need to look at the code to see where it happens. Looks like it is trying to launch something.

    Error: Error #2176: Certain actions, such as those that display a pop-up window, may only be invoked upon user interaction, for example by a mouse click or button press.
    at flash.net::FileReference/download()
    at src.file::FileManager/download()
    at src::ImageCreator/onDownloadImage()
    at src::ImageCreator/onImageCreated()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

    7:21 am / July 10th, 2009

  8. danno said…

    @mw & @dane :
    that error is coming up because of the changes to security in flash 10. to have something be downloaded by the user, it must be from an action on a button, ie: user interaction, not just a background process. flash 9 player, you don’t. read this article to see how to change and update it:
    http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes_02.html#head3

    but to make the script work , open up ImageCreator.as . navigate to function onImageCreated .

    at the bottom of the function, where it says:
    onDownloadImage();

    just comment that last part out. that’s it. so now you’ll have the following:

    private function onImageCreated ( e : Event ) : void
    {
    trace( ‘image created : ‘ + e );

    // hide image creation message;
    TweenFilterLite.to( creating, 1, { autoAlpha : 0 } );

    // show download button;
    TweenFilterLite.to( download, 0.5, { autoAlpha : 1 } );

    // show download dialog for flash player versions < 10;
    //onDownloadImage();
    }

    hope that helps :)

    rocksteady,
    danno~

    8:22 pm / July 24th, 2009

  9. Chris said…

    Awesome Script! I was wondering if there was anyway to resize the image client size, instead of uploading a huge image and then resizing it. This would save alot of server time. Is it possible?

    12:09 pm / September 10th, 2009

  10. james cumagh said…

    Hi, thanks a lot for sharing this code, i’m new to as3 and can’t figure out where the image is actually loaded once i selected a file… i’m planning to load the image in a movieClipA inside a movieClipB, wherein the movieClipB will be the capture area…

    1:37 am / February 11th, 2010

  11. mika said…

    Hi

    Great code!
    I have spent the night trying to make a unique file name on upload, and failed. Any tip ?

    9:52 pm / July 6th, 2010

  12. mika said…

    Ok got it

    Change
    private function uploadCompleteDataHandler ( e : DataEvent ) : void
    {
    dispatchEvent( new CustomEvent( ON_IMAGE_UPLOADED, { fileName : m_fileName+”_example”" } ) );
    }

    in FileMananger.as and PHP script (move_uploade_file function) accordingly

    9:04 am / July 8th, 2010

  13. Barry said…

    I dont get it, last week i got an entirely different structure in the source. And when i try this one it works on my drive but when i alter the pats etc, and upload it nothing seems to work.
    Am i getting mad?

    2:46 am / September 23rd, 2010

  14. Barry said…

    Okay the above problem is fixed, i found the older version again, but still cant get it to work :(

    The line goes to 100% and stays there, it doesn’t upload a picture and i cant even download it, it just hangs when loading it

    1:43 am / September 24th, 2010

  15. Brent said…

    Thanks Shaun, this helped a lot. But I am running into and odd problem. My upload works perfectly in flash or in a stand alone .exe but fails when in a web browser. In fact it appears to fail in the browser anytime I add a property to urlRequest.data. Is there something I am missing?

    1:56 pm / October 5th, 2010

  16. sizom said…

    Hi,
    I would like to know how to do to loading image always be above other movieclips on the stage??

    Thanks in advance

    7:31 am / March 3rd, 2011

  17. Vishwas said…

    well, it doesnot work for me :(
    Not only this one, i have tried many other upload scripts, but they don’t work. ( They work locally using xampp btw )
    I think i have tried everything. The tiny grey upload bar below the upload button, shows full upload. But doesnot upload anything. By server folder is at 777 .
    :(

    11:16 am / June 12th, 2011

Have a comment?