How to automate the capture of Gi''s or Jpg"s from a Flash program.

Posted on 2007-08-08
Last Modified: 2013-11-19

We have a specification to develop data driven graphics for one of the projects in our shop. Weve prototyped this with Flash using an Xml file from our database and ActionScript to arrange and color the elements within our graphic.

All works well except were at a loss to generate the Gif or Jpg files. If we publish to a Gif or Jpg, we only get the Flash Frame without the action scripts running (thus no population of the data).  If we run the swf file the graphic is populated, but we then have to capture the graphic by hand with another tool.  Would any of you know how to automate the process to capture several hundred Gifs or Jpgs?


Bill Fleury
Question by:Fleurys
    LVL 39

    Expert Comment

    Hi, i'm not understanding your question, but your application is supposed to load an image, arrange it and color it then output an image? is that right?
    you won't be able to achieve that in flash alone, not sure what you'd use, but first lets pinpoint if that's what you mean.

    Author Comment

    No, the swf reads an xml file and uses this information to draw the appropriate graphic in Flash. Once the graphic has been rendered we then need to export it to a Jpg. The export process is what I'm inquiring about; it should be some form of atomation as we will have to do this for several hundred graphics.

    LVL 10

    Expert Comment

    Flash SWF's and executables don't have the ability to export and save JPG (or any other) graphics natively. (the flash environment does, but that's different)

    Author Comment

    I thank the both of your for your response's, it's nice to correspond with people who are familiar with the Flash product.

    I've taken note of your point,  but is there not a workaround or non-native soltion to this problem. A solution that requires some programming (ms visual studio) or something that works in combination with another program would be acceptible. It has to be an automated process though, we can't have someone doing them one at a time.
    LVL 39

    Expert Comment

    a few years ago my then boss decided i have to create a flash collaborative whiteboard where the users can draw and write to their heart's content and then click a button and it saves the content as a jpeg on the users harddrive.
    Hence, she's no longer my boss :-)

    seriously, i'm sure it can be done, but not with flash. I remember speaking to a java programmer who went off about storing the pixels as bits with their colour properties and then remapping those pixels and applying them.... at that point I lost interest.

    You might want to post the question in the programming section, one of them might be able to help you.
    LVL 10

    Expert Comment

    It may be possible in flash with, for example VB etc. I know you can load an SWF into there and therefore you could have some kind of collaborative solution. Have a go at putting an SWF object into one of the visual studio languages you're familiar with and see how that progresses. I haven't a clue how to do things like screen grabs and the like in VB / C++ but presumably it can't be that hard. Then you just have to save whatever you've grabbed as a JPEG.
    LVL 9

    Accepted Solution

    This is fun - a task with numberous solutions...
    For now - three ideas to get you started

    1) Do you need a jpeg output?
    Couldn't you just record the changes and then reproduce the image in flash using the
    source and the recorded data?

    2) Try take a look at flash's BitmapData it may be (F1) helpfull

    3) If you need to save images you must pass the image info to the server to handle the
        "FSO-thing" or whatever component or such you have available.
    ~ Jakob E
    LVL 5

    Assisted Solution

    I had the similar task several years ago.
    The most suitable method I know is to use any good screen capture program in conjunction with automation utility (I prefer , it is free).
    If automation utility is flexible enough, you can even make "PrintScreen - Paste in Photoshop - Crop - Save for Web" sequence, although it is rather odd way.
    Or simply use screen capture program that creates png screenshot by pressing hotkey, you can set it up to capture only the screen region you need or you can make a batch crop later in Photoshop.

    Note: it may be better to create "debug mode" actionscript for your flash to sequence all the screens you need to capture. Maybe changing frames by pressing "spacebar", it will be easier to automate via automation utility. This could save you many hours if you will need to repeat the procedure later.

    Author Comment

    Thanks all for your responses,

    Ive made a little progress, some with your suggestions and some on my own initiative. Basically, Ive used an application called SnagIt (cost $40) which among its other attributes has the ability to establish a printer port that it will monitor (similar to a PDF Printer in Adobe Acrobat). Within the action script Ive issued a print command which causes a dialog box to appear, I choose the appropriate printer and the SnagIt Program will then grab the image, crop it and save it as a jpg into a predefined folder.

    This process works well for one image. I then modified the action script to first accept a master list which contains the names of all the data xml files to convert. A second routine will then read each data xml file in turn and issue a print command (using the print.addpage method. This should output a single multipage document which SnagIt or Acrobat can both be configured to export as single page jpgs.

    My current problem has to do with opening the data xml files in the second routine. It seems once Ive opened an xml file, the second attempt to declare and open an xml file fails and returns a null. Im not certain whats going on. Do any of you have any ideas ?



    PS. Jakob  I not certain I have a need for the BitmapData  in actionscript, but it sounds interesting and Ill try to read through it today.

    The blasted One: - Ive taken a look at the Auto HotKey program but believe I stay with SnagIt for now.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
    I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
    The goal of the tutorial is to teach the user how to how to record live broadcast.
    Not only does Prezi allow you to create non-linear presentations, it also makes it easy to apply transition animations between your frames. Learn how to apply a fade-in transition to select items and entire frames in this tutorial Select "Edit Path"…

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now