rar: http://www.sandy1219.com/python/python-swf.rar
connectSwf.py
<textarea cols="50" rows="15" name="code" class="python:collapse:showcolumns">import wx; import os; from wx.lib.flashwin import FlashWindow; #from xml.dom import minidom; class ConnectSwf(wx.Frame): def __init__(self): wx.Frame.__init__(self,None,-1,title="swf",size=(400,300),style=wx.DEFAULT_FRAME_STYLE^(wx.RESIZE_BORDER|wx.MAXIMIZE_BOX)); #print os.getcwd(); self.swfPanel = SWFgui(self); self.setBtn = wx.Button(self,wx.NewId(),"set"); self.Bind(wx.EVT_BUTTON, self.setFlash, self.setBtn); self.getBtn = wx.Button(self,wx.NewId(),"get"); self.Bind(wx.EVT_BUTTON, self.getFlash, self.getBtn); self.playBtn = wx.Button(self,wx.NewId(),"play"); self.Bind(wx.EVT_BUTTON,self.startPlay,self.playBtn) self.stopBtn = wx.Button(self,wx.NewId(),"stop"); self.Bind(wx.EVT_BUTTON,self.endPlay,self.stopBtn) mainSizer = wx.BoxSizer(wx.VERTICAL); mainSizer.Add(wx.StaticLine(self),0,wx.EXPAND); btnSizer1 = wx.BoxSizer(wx.HORIZONTAL); btnSizer1.Add((20,20),1); btnSizer1.Add(self.setBtn); btnSizer1.Add((20,20),1); btnSizer1.Add(self.getBtn); btnSizer1.Add((20,20),1); btnSizer2 = wx.BoxSizer(wx.HORIZONTAL); btnSizer2.Add((20,20),1); btnSizer2.Add(self.playBtn); btnSizer2.Add((20,20),1); btnSizer2.Add(self.stopBtn); btnSizer2.Add((20,20),1); mainSizer.Add(btnSizer1,0,wx.EXPAND|wx.ALL,10); mainSizer.Add(btnSizer2,0,wx.EXPAND|wx.ALL,10); mainSizer.Add(self.swfPanel,0,wx.EXPAND|wx.ALL,10); self.SetSizer(mainSizer); mainSizer.Fit(self); mainSizer.SetSizeHints(self); def startPlay(self,event): self.swfPanel.flash.ctrl.CallFunction(self.formatXML("playFlash" ,"" )) def endPlay(self,event): self.swfPanel.flash.ctrl.CallFunction(self.formatXML("stopFlash" , "")) def setFlash(self,event): self.swfPanel.flash.ctrl.CallFunction(self.formatXML("ExternalReceiver", str( range(5) )) ) def getFlash(self,event): self.swfPanel.flash.ctrl.CallFunction(self.formatXML("getFlash" , "")) def OnProgress(self,event): print event; def FlashCall(self, xmlStr): print "FlashCall" dlg = wx.MessageBox(xmlStr,"from flash"); #def parserXML(self,xmlStr): # xmldoc = minidom.parseString(xmlStr); # print xmldoc.toXML(); #return xmlStr; def formatXML(self,flashFunctionName='',sendStr=''): xmlStr = "<invoke name=/"" + flashFunctionName + "/" returntype=/"xml/">" xmlStr += "<arguments>" xmlStr += "<string>" + sendStr + "</string>" xmlStr += "</arguments>" xmlStr += "</invoke>" return xmlStr; class SWFgui(wx.Panel): def __init__(self,parent): wx.Panel.__init__(self,parent,-1,pos=(0,0),size=(400,300),style=wx.FRAME_SHAPED); self.flash = FlashWindow(self,style=wx.SUNKEN_BORDER,size=(400,300)); wx.BeginBusyCursor(); self.flash.AddEventSink(parent); self.flash.LoadMovie(0, os.path.join(os.getcwd(),"pythonswf.swf")); self.flash.SetSize((400,300)) wx.EndBusyCursor(); print self.flash.FlashVersion(); def getText(self): return self.flash.GetVariable("var1"); def setText(self,text): self.flash.SetVariable("var2", text); if __name__ == "__main__": app = wx.PySimpleApp(); frame = ConnectSwf(); frame.Center(); frame.Show(); app.MainLoop(); </textarea>
flash:
<textarea cols="50" rows="15" name="code" class="c-sharp:collapse:showcolumns">function externHandler(externalStr:String){ txt.text = "from python: " + externalStr; } function stopFlashHandle(s){ this.stop(); } function playFlashHandle(s){ this.play() } if (ExternalInterface.available) { ExternalInterface.addCallback("playFlash",playFlashHandle); ExternalInterface.addCallback("stopFlash",stopFlashHandle); ExternalInterface.addCallback("ExternalReceiver",externHandler); ExternalInterface.addCallback("getFlash",getFlash); } b.buttonMode = true; b.addEventListener(MouseEvent.CLICK , clickHandle); function getFlash(s){ clickHandle(); } function clickHandle(e:MouseEvent=null){ ExternalInterface.call("externCall", txt.text); } </textarea>