pythonCOM with Flash

Bradley Schatz bradley at
Sat Jun 14 11:41:25 CEST 2003

Thanks Mark - Distributed testing pays off again.:) What didnt work on my
work pc worked on yours and also my home pc. I am pleased to report that
events work as expected too.

> I'm uninterested in flash :)  I use Mozilla as my day-to-day browser for
> a number of reasons, and am happy that I actually need to go out of my
> way to enable flash support there.

I cant say that I have bothered to get flash working under my linux mozilla.
My primary interest is using flash as the UI for python apps (on win32 of
course). Not because I want to learn yet another gui toolkit, but because
creative types seem pretty comfortable designing really good looking UI
prototypes in flash.

A couple of sites have covered this from a VB perspective - this article
covers it in depth

Find a working demo attached below - click on the sphere in the flash
window, and python will respond and change the gui based on the event.

My next goal is to get this working outside of pythonwin, as a standard app.
Any further suggestions on how how to throw together a simple activex gui


# simple flash/python application demonstrating bidirectional communicaion
# flash and python. Click the sphere to see behavior.
# Uses Bounce.swf from, available from
# make sure this .py has the right filesystem path to the swf
import win32ui, win32con, win32api, regutil
from pywin.mfc import window, activex
from win32com.client import gencache
import sys

FlashModule =
gencache.EnsureModule("{D27CDB6B-AE6D-11CF-96B8-444553540000}", 0, 1, 0)

if FlashModule is None:
 raise ImportError, "Flash does not appear to be installed."

class MyFlashComponent(activex.Control, FlashModule.ShockwaveFlash):
 def __init__(self):
  self.x = 50
  self.y = 50
  self.angle = 30
  self.started = 0

 def OnFSCommand(self, command, args):
  print "FSCommend" , command, args
  self.x = self.x + 20
  self.y = self.y + 20
  self.angle = self.angle + 20
  if self.x > 200 or self.y > 200:
      self.x = 0
      self.y = 0
  if self.angle > 360:
      self.angle = 0
  self.SetVariable("xVal", self.x)
  self.SetVariable("yVal", self.y)
  self.SetVariable("angle", self.angle)

 def OnProgress(self, percentDone):
  print "PercentDone", percentDone
 def OnReadyStateChange(self, newState):
  # 0=Loading, 1=Uninitialized, 2=Loaded, 3=Interactive, 4=Complete
  print "State", newState

class BrowserFrame(window.MDIChildWnd):
 def __init__(self, url = None):
  if url is None:
   self.url = regutil.GetRegisteredHelpFile("Main Python Documentation")
   self.url = url
  pass # Dont call base class doc/view version...
 def Create(self, title, rect = None, parent = None):
  style = win32con.WS_CHILD | win32con.WS_VISIBLE |
  self._obj_ = win32ui.CreateMDIChild()
  self._obj_.CreateWindow(None, title, style, rect, parent)
  rect = self.GetClientRect()
  rect = (0,0,rect[2]-rect[0], rect[3]-rect[1])
  self.ocx = MyFlashComponent()
  self.ocx.CreateControl("Flash Player", win32con.WS_VISIBLE |
win32con.WS_CHILD, rect, self, 1000)
  self.HookMessage (self.OnSize, win32con.WM_SIZE)

 def OnSize (self, params):
  rect = self.GetClientRect()
  rect = (0,0,rect[2]-rect[0], rect[3]-rect[1])
  self.ocx.SetWindowPos(0, rect, 0)

def Demo():
 url = None
 if len(sys.argv)>1:
  url = win32api.GetFullPathName(sys.argv[1])
 f = BrowserFrame(url)
 f.Create("Flash Player")

if __name__=='__main__':

More information about the Python-list mailing list