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