Integrate with Flash MX

Alan Kennedy alanmk at hotmail.com
Fri Sep 27 06:41:14 EDT 2002


Peter Bengtsson wrote:
> I want to use Flash MX to build a GUI for use on the desktop on
> windows, not embedded in a webpage.
> ActionScripts don't do it for me so I want to use Python for the
> business logic.
> 
> Is there some way to enable this connection? Maybe this is more of a
> Flash question.

Hmm, I haven't actually done this, but there are two possible approaches
I can think of.

Method 1. Use the python win32 extensions to control the Flash Player
COM object directly. You create the COM object as follows

code----
import from win32com.client import Dispatch
fl = Dispatch('ShockwaveFlash.ShockwaveFlash.6')
code----

>From now you control the Flash COM object 'fl' from python. I don't
know what the methods of the Flash COM object are, nor do I know
a reference where you can find them. If you do come across such a
reference, I'd love to hear about it.

Also, I'm not sure how you would achieve interaction between the
UI elements in the Flash movie and your python objects. I'm not sure
if this can be done without resorting to ActionScript. I suppose it
depends on the interface presented by the Flash COM object. The nature
of the communication *should* be similar to the two-way communication
between DHTML scripting languages and Flash which is described below.

Method 2. 

I know you said that you don't want to embed the GUI inside a web page.
However doing that would make you task so very much simpler, that it
might be worth considering. Also, perhaps it might be possible to control
Internet Explorer behind the scenes with win32com?

Embed the Flash movie representing your GUI inside a HTML page, and
use Internet Explorer as the "intermediator" between your Flash GUI
and your python logic. 

On the Python side, you write your Python as a DHTML scripting
language. The Python win32 extensions permit you to do this. I think
it goes something like

<script language="python">
    def petshop():
        print "Man:        Good morning, I'd like to buy a cat. "
        print "Shopkeeper: Certainly sir. I've got a lovely terrier."
        print "            [indicates a box on the counter]"
        print "Man:        No, I want a cat really."
        print "Shopkeeper: [taking box off counter and then putting"
        print "            it back on counter as if it is a different"
        print "            box] Oh yeah, how about that?"
        print "Man:        [looking in box] No, that's the terrier."
        print "Shopkeeper: Well, it's as near as dammit."
        print "Man:        Well what do you mean? I want a cat."
        print "Shopkeeper: Listen, tell you what. I'll file its legs"
        print "            down a bit, take its snout out, stick a"
        print "            few wires through its cheeks. There you"
        print "            are, a lovely pussy cat."
        print "Man:        Its not a proper cat."
        print "Shopkeeper: What do you mean?"
        print "Man:        Well it wouldn't meow."
        print "Shopkeeper: Well it would howl a bit."
        print "Man:        No, no, no, no. Er, have you got a parrot?"
</script>

On the Flash side, you will need to use "fscommand"s to communicate out
to the (D)HTML thatr contains your python objects.

For an example of this kind of communication, see the following
Macromedia reference. Wherever you see "Javascript", substitute
that for "PythonScript", i.e. Python running as a DHTML scripting
language.

http://www.macromedia.com/support/flash/ts/documents/java_script_comm.htm

> Anybody got any experience with this?

Sorry, it's an unusual approach that you're using, i.e. integrating
python and Flash. I've never even considered it (until now), let alone
implemented it. I've never heard of anyone doing it.

Is there any particular reason why you don't like ActionScript? I
know version 4 was fairly limiting, but version 5 has really cleaned
up the language a lot, and you can achieve quite a bit.

I'd love to know how you get on with this.

Best of luck,

alan kennedy
----------------------------------------------
check http headers here: xhaus.com/headers
email alan:              xhaus.com/mailto/alan



More information about the Python-list mailing list