How do you download product images from a SWF file?

Posted on 2009-04-28
Last Modified: 2012-05-06
I have a small web site that would have about 25 product images. I would like to have a prospect be able to click on a product image and have it download to their desktop either as low resolution or as a high resolution zipped file.

How do you do this using Actionscript 2?
Question by:rgroft
    LVL 8

    Expert Comment

    To download as a zip, all you need is getURL, since the browser won't attempt to open it anyway - you will get a "save as" dialog.

    btn.onRelease = function(){

    If you want to download an image as an attachment, things get a little trickier since the default behaviour will be to just display the image. Uou will need a little server-side help to tell the browser it should download the file as an attachment rather than attempting to display it.

    Here is an example of how the server side component would work in ColdFusion - there are of course equivalents for ASP or PHP, depending on your favourite:

    To use this, you would simply create a server page called "download.cfm" which contains this code and use this Actionscript to call it

    btn.onRelease = function(){

    If server-side stuff isn't your thing you can get away with just opening the image in a new window, and instructing the user to right-click and "save-as" the image. The following actionscript will open your image in a blank window

    btn.onRelease = function(){
        getURL("image.jpg","_blank" );


    Author Comment

    Hi ccarey!

    The  "getURL("image.jpg","_blank" );" works. Thank you!

    I tried the ColdFusion attempt and the only thing that shows up in the browser window is the "download.cfm" code. I have no clue how to do this one unfortunately.

    If I have an image called Pic01, where would I place it in the coding? The cfm or the button code. Also, Would the ASP version be easier?

    LVL 8

    Accepted Solution

    You would need to be hosted on a ColdFusion server for it to process a .cfm file. To use ASP your server needs to be able to interpret ASP. Same for PHP and so on. You'd need to ask your web host what they support.

    If your image is called Pic01.jpg your server page would need to be told what file to download - I used ?file=blah below to get the filename from the URL.


    Here's an equivalent PHP sample:

    // We'll be outputting an image
    header('Content-type: image/jpg');

    // It will be called Pic01.jpg
    header('Content-Disposition: attachment; filename="Pic01.jpg"');

    //  read the image source

    If you google around for ASP content-type header you'll find an ASP equivalent. All the server languages have some permutation of the same thing. Essentially it's just telling your browser "do this with the content I'm supplying"

    Author Closing Comment

    Thank you for your help. i will check out the ASP style.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
    Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
    The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
    This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now