3

I'm having an app where the user can edit a simple greeting card and should be able to send it to another user. We are currently doing it by exporting to a 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!

Community
  • 1
  • 1
David Salzer
  • 872
  • 1
  • 7
  • 24

2 Answers2

5

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
  • 64,916
  • 15
  • 117
  • 140
  • Thank you, and again for adding the code. Michael's question is importamt however. – David Salzer Sep 26 '09 at 22:11
  • Yes it does! It even works in reverse too! (Load a .swf and it'll be castable to MovieClip). – LiraNuna Sep 26 '09 at 22:37
  • LiraNuna- Thanks! Do you know if it will work with Canvas too? (I will try myself and publish results later) – David Salzer Sep 28 '09 at 19:40
  • I believe only MovieClip has this luxury. I didn't work much with Flex so I might be wrong. – LiraNuna Sep 28 '09 at 23:38
  • @LiraNuna - This seems very interesting but I can't get it working. I'm trying to save a MovieClip to a swf file through AIR, but the ByteArray never has more than 1 byte available to read after calling writeObject(movieClip). I'm also unsure what the '...' represents for the argument here in "buffer.writeBytes(...);" Are you writing the buffer back into itself? It sounds like you did get this working so if you could post more complete examples I'd be grateful. There doesn't appear to be anything on the web about this technique. – Dane Nov 04 '10 at 19:01
  • 1
    This technique does not work on newer players. I am still actively seeking for a way to deep copy a MovieClip. This method was suitable for flash player 9, while 10 doesn't like it. – LiraNuna Nov 06 '10 at 18:51
1

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
  • 7,499
  • 4
  • 36
  • 35