|
Introduction
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:
A live demo can be found on the PyAMF blog.
Grab the example from SVN with:
svn export http://svn.pyamf.org/pyamf/trunk/doc/tutorials/examples/actionscript/bytearray bytearray-example
cd bytearray-example/python
Alternatively, if you just want to have a look, you can browse the example online.
Note: Make sure you have Django >= 0.96 installed.
The remoting gateway for the Adobe Flash Player and Python AMF clients starts on http://127.0.0.1:8000 when you launch the development server:
python manage.py 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 http://127.0.0.1:8000/
Quit the server with CONTROL-C.
You can start the development server on a different host/port like this:
python manage.py runserver 192.168.1.100:8080
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:
python client.py
You should see something like this for the client:
Found 1 snapshot(s):
http://127.0.0.1:8000/images/django-logo.jpg
Saved snapshot:
snapshot_x_M527.jpg: http://127.0.0.1:8000/images/snapshot_x_M527.jpg
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>)
</Envelope>
[2009-12-26 14:08:15,026 root DEBUG] AMF Response: <Envelope amfVersion=0>
(u'/1', <Response status=/onResult>['http://127.0.0.1:8000/images/', ['jpg', 'png'],
<flex.messaging.io.ArrayCollection [{'name': 'django-logo.jpg'}]>]</Response>)
</Envelope>
[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>)
</Envelope>
[2009-12-26 14:08:15,034 root DEBUG] AMF Response: <Envelope amfVersion=0>
(u'/2', <Response status=/onResult>{'url': u'http://127.0.0.1:8000/images/snapshot_x_M527.jpg',
'name': u'snapshot_x_M527.jpg'}</Response>)
</Envelope>