views:

366

answers:

2

Hi All.

Im having an app where the user can edit a simple greeting card and should be able to send it to another user. We currently doing it by exporting to graphic file and sending with some server script.

Now - we found a need to export that card to swf. This card is basically a (Flex) Canvas holding some images and labels.

What do you say? can that be done? Any help will be appreciated.

Thanks!

+3  A: 

Deep copy the MovieClip object to a ByteArray and dump it to a file.

var buffer:ByteArray = new ByteArray();
buffer.writeObject(MOVIE_CLIP_HERE);
buffer.position = 0;
buffer.writeBytes(...);
LiraNuna
Does that save it directly to a SWF format?
Michael Todd
Thank you, and again for adding the code. Michael's question is importamt however.
yn2
Yes it does! It even works in reverse too! (Load a .swf and it'll be castable to MovieClip).
LiraNuna
Wow! That's fantastic; and great information. Thanks.
Michael Todd
LiraNuna- Thanks! Do you know if it will work with Canvas too?(I will try myself and publish results later)
yn2
I believe only MovieClip has this luxury. I didn't work much with Flex so I might be wrong.
LiraNuna
A: 

server side flex sdk compiles actionscript or flex from the command line on any linux/unix/windows machine

I use the flex command line compiler to develop flash apps from my linux desktop, will work great on a server and is scriptable from your web app.

here are the steps

1.) download the flex sdk from adobe, and unzip it on the server

2.) generate the actionscript *.as file or flex *.mxml file for the card

3.) run this in a linux shell on the server to generate the SWF

SOURCE_FILE=/dir/with/flex_sdk/

OPTS='-use-network=false'
# note this is a relative path to the flex sdk
CONFIG_FILE='flex-config.xml'

if [ -f $CONFIG_FILE ]; then
    OPTS=$OPTS' -load-config='$CONFIG_FILE
fi

OPTS=$OPTS' -output /path/to/ouput/swf'

/path/to/flex_sdk/bin/mxmlc $OPTS $SOURCE_FILE

the sdk works on windows also but I'm not sure what the command line arguments are

Fire Crow
Why the hassle? Flash saves flash.display.MovieClip internally as a .swf object directly! see my answer for more information.
LiraNuna
yes you have made your solution clear above...
Fire Crow