ExternalInterface , between python and flash

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=&quot;swf&quot;,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(),&quot;set&quot;); self.Bind(wx.EVT_BUTTON, self.setFlash, self.setBtn); self.getBtn = wx.Button(self,wx.NewId(),&quot;get&quot;); self.Bind(wx.EVT_BUTTON, self.getFlash, self.getBtn); self.playBtn = wx.Button(self,wx.NewId(),&quot;play&quot;); self.Bind(wx.EVT_BUTTON,self.startPlay,self.playBtn) self.stopBtn = wx.Button(self,wx.NewId(),&quot;stop&quot;); 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(&quot;playFlash&quot; ,&quot;&quot; )) def endPlay(self,event): self.swfPanel.flash.ctrl.CallFunction(self.formatXML(&quot;stopFlash&quot; , &quot;&quot;)) def setFlash(self,event): self.swfPanel.flash.ctrl.CallFunction(self.formatXML(&quot;ExternalReceiver&quot;, str( range(5) )) ) def getFlash(self,event): self.swfPanel.flash.ctrl.CallFunction(self.formatXML(&quot;getFlash&quot; , &quot;&quot;)) def OnProgress(self,event): print event; def FlashCall(self, xmlStr): print &quot;FlashCall&quot; dlg = wx.MessageBox(xmlStr,&quot;from flash&quot;); #def parserXML(self,xmlStr): # xmldoc = minidom.parseString(xmlStr); # print xmldoc.toXML(); #return xmlStr; def formatXML(self,flashFunctionName='',sendStr=''): xmlStr = &quot;&lt;invoke name=/&quot;&quot; + flashFunctionName + &quot;/&quot; returntype=/&quot;xml/&quot;&gt;&quot; xmlStr += &quot;&lt;arguments&gt;&quot; xmlStr += &quot;&lt;string&gt;&quot; + sendStr + &quot;&lt;/string&gt;&quot; xmlStr += &quot;&lt;/arguments&gt;&quot; xmlStr += &quot;&lt;/invoke&gt;&quot; 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(),&quot;pythonswf.swf&quot;)); self.flash.SetSize((400,300)) wx.EndBusyCursor(); print self.flash.FlashVersion(); def getText(self): return self.flash.GetVariable(&quot;var1&quot;); def setText(self,text): self.flash.SetVariable(&quot;var2&quot;, text); if __name__ == &quot;__main__&quot;: 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 = &quot;from python: &quot; + externalStr; } function stopFlashHandle(s){ this.stop(); } function playFlashHandle(s){ this.play() } if (ExternalInterface.available) { ExternalInterface.addCallback(&quot;playFlash&quot;,playFlashHandle); ExternalInterface.addCallback(&quot;stopFlash&quot;,stopFlashHandle); ExternalInterface.addCallback(&quot;ExternalReceiver&quot;,externHandler); ExternalInterface.addCallback(&quot;getFlash&quot;,getFlash); } b.buttonMode = true; b.addEventListener(MouseEvent.CLICK , clickHandle); function getFlash(s){ clickHandle(); } function clickHandle(e:MouseEvent=null){ ExternalInterface.call(&quot;externCall&quot;, txt.text); } </textarea>

你可能感兴趣的:(python,function,Flash,import,button,border)