This page describes how to setup the ByteArray example application using the Flex SDK and Django.

The ByteArray class in Actionscript 3.0 provides methods and properties to optimize reading, writing, and working with binary data used in the Adobe Flash Player 9 and newer.


This example demonstrates how to:

  • Create a webcam snapshot by capturing the BitmapData using Flex
  • Wrap the image data with the ByteArray class and send it to a PyAMF remoting gateway
  • Use Python to write the JPG file to disk
  • Run a simple webserver for static content that serves the JPG files
  • Use Flex to load the JPG and display it in the application

A live demo can be found on the PyAMF blog.


Clone the PyAMF repository with:

git clone git:// pyamf
cd doc/tutorials/examples/actionscript/bytearray/python

Alternatively, if you just want to have a look, you can browse the example online.


Note: Make sure you have Django >= 1.0 installed.

The remoting gateway for the Adobe Flash Player and Python AMF clients starts on when you launch the development server:

python runserver

You should see something like:

Validating models...
0 errors found

Django version 1.1.1, using settings 'python.settings'
Development server is running at
Quit the server with CONTROL-C.

You can start the development server on a different host/port like this:

python runserver


Flash Player

You can simply open the SWF file and it will connect to http://localhost:8000.

Press the ‘Create snapshot’ button to make snapshots and save them to disk. You can see the snapshots in the View tab. The snapshots are saved in the python/gateway/images folder.



The Python AMF client can be started by running the following from the python folder:


You should see something like this for the client:

Found 1 snapshot(s):
Saved snapshot:

And the server prints:

[2009-12-26 14:08:15,023 root DEBUG] remoting.decode start
[2009-12-26 14:08:15,024 root DEBUG] Remoting target: u'getSnapshots'
[2009-12-26 14:08:15,024 root DEBUG] remoting.decode end
[2009-12-26 14:08:15,024 root DEBUG] AMF Request: <Envelope amfVersion=0>
  (u'/1', <Request target=u'getSnapshots'>[]</Request>)
[2009-12-26 14:08:15,026 root DEBUG] AMF Response: <Envelope amfVersion=0>
  (u'/1', <Response status=/onResult>['', ['jpg', 'png'],
< [{'name': 'django-logo.jpg'}]>]</Response>)
[26/Dec/2009 14:08:15] "POST / HTTP/1.1" 200 149
[2009-12-26 14:08:15,032 root DEBUG] remoting.decode start
[2009-12-26 14:08:15,033 root DEBUG] Remoting target: u'ByteArray.saveSnapshot'
[2009-12-26 14:08:15,033 root DEBUG] remoting.decode end
[2009-12-26 14:08:15,033 root DEBUG] AMF Request: <Envelope amfVersion=0>
 (u'/2', <Request target=u'ByteArray.saveSnapshot'>
         [<pyamf.amf3.ByteArray object at 0x102266c08>, u'jpg']</Request>)
[2009-12-26 14:08:15,034 root DEBUG] AMF Response: <Envelope amfVersion=0>
 (u'/2', <Response status=/onResult>{'url': u'',
                                     'name': u'snapshot_x_M527.jpg'}</Response>)


When you run python –help it will display the various options available for this example client:

Usage: [options]

  -h, --help            show this help message and exit
  -p PORT, --port=PORT  port number [default: 8000]
  --host=HOST           host address [default:]