python interoperability array help

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

jeff_o
Posts: 13
Joined: 03 Oct 2008, 20:59

python interoperability array help

Postby jeff_o » 28 Jan 2009, 18:01

I am trying to send an internal request from an actionscript extension to a python extension. I want to send an array to the python extension and could not find any documentation on how to do this. Any help would be much appreciated!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 29 Jan 2009, 10:12

Exchanging language specific data structures is a little complicated, you can do it if you know the details behind the Rhino and Jython engines otherwise I would use another way.

What I would suggest is to pass native Java data structures across extensions/servlets running in different languages. Both Python and Actionscript have full access to java objects, so they provide a "common ground" for both environments.

You can use ArrayList, LinkedList for array based data, and HashMap (or ConcurrentHashMap if you need thread safety) for associative arrays/dictionaries
Lapo
--
gotoAndPlay()
...addicted to flash games
jeff_o
Posts: 13
Joined: 03 Oct 2008, 20:59

Postby jeff_o » 29 Jan 2009, 17:31

If it is not too much trouble, an example of how to do this would be really helpful!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 30 Jan 2009, 06:18

supposing you're trying to send a list of strings from a Python extension to an AS extension...

Code: Select all

from java.util import ArrayList
theList = ArrayList()
theList.add("Hello")
theList.add("World")

theASExtension.handleInternalRequest(theList)

on the AS side:

Code: Select all

function handleInternalRequest(obj)
{
   trace("Array size: " + obj.size())
}


For all the details about collections in Java, check the J2SE javadoc --> http://java.sun.com/j2se/1.5.0/docs/api/
The package is java.util.collection
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 15 guests