From flashticle import swf

During the reading of one of the articles at osflash I’ve got inspiration (and portion of the code) from flashticle project to start with a little project by myself (called pyswf).
That’s not *really* a project, also because there are so many decrypers, disassemblers, optimizators etc around here, but more an exercize for better understand both python and the SWF file format…
BTW, currently it can read quite almost all swf tags and actions, writing them in a pseudo-code (later i will try to create the original actionscript code), and also extract some of the swf embedded multimedia objects (such as flv, mp3, wav, and images)
for example:
main -e "test.swf"
it will print all the swf code in the output buffer and also extract all the multimedia files embedded into test.swf
you can download the source code (with also a win32 binary) from here

Flash remoting for python

Yesterday I received an email form Vsevolod ILyushchenko announcing me the alpha version of Flash remoting for python!
http://simonf.com/amfpython/. There are also many examples here: http://simonf.com/amfpython/code.html

Second update: Serializer Class 2.1
There is a bug fixing with in special chars lenght, thanks to Rainer Becker. The new mxp file is available on the sourceforge site.

Last thing. I’ve just uploaded an example which Daniel Tavelli send me.
An example of Xpath usage in flash mx 2004 using the xfactorstudio xpath class for ActionScript

wxPython and Flash, first test


Today I make the first test integrating a Flash movie into a python application and using a communication between the two applications using FSCommand and the flashvars.
The result (surprendent easy) it’s a simple movie which enables text files saving in the local computer (through a prompt dialog window), but it has already opened my mind to future real cool applications 😉

This is the python code, the core part it’s the “wx.lib.flashwin” import, which enable to use Flash ActiveX in a python frame

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx, sys, os
import string, codecs
from wx.lib.flashwin import FlashWindow
from wx.lib.flashwin import EVT_FSCommand
#----------------------------------------

class TestPanel(wx.Panel):
    def __init__(self, parent, base, swf):
        wx.Panel.__init__(self, parent, -1)
        self.base = base
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.flash = FlashWindow(self, style=wx.SUNKEN_BORDER)   
        dlg = wx.MessageDialog(self, "This will work only under Windows!","Warning!",wx.OK | wx.ICON_INFORMATION)
        dlg.Center()
        dlg.ShowModal()        
        wx.BeginBusyCursor()
        try:
            self.flash.LoadMovie(0, swf)
        except:
            wx.MessageDialog(self, "could not load the swf file","Error",wx.OK | wx.ICON_ERROR).ShowModal()
            sys.exit(2)
        wx.EndBusyCursor()        
        self.flash.Stop()      
        self.flash.SetSize((self.flash.GetSize()[0],self.flash.GetSize()[1]))
        # sizer
        sizer.Add(self.flash, 1, wx.EXPAND)
        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        sizer.Fit(self)
        sizer.SetSizeHints(self)        
        self.SetFlashOptions()
        self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
        self.Bind(EVT_FSCommand, self.CallMethod)
        
    def SetFlashOptions(self):
        self.flash.menu = False
        self.flash._set_FlashVars("data=Server started on " + sys.platform)
        self.flash.Play()
        
    def OnDestroy(self, evt):
        if self.flash:
            self.flash.Cleanup()
            self.flash = None

    # Called from Flash FSCommand
    def CallMethod(self, evt):
        try:
            arguments = string.split(evt.args,"###")
            filename = arguments[0]
            body = arguments[1]
            if filename == "" or body == "":
                wx.MessageDialog(self, "Please check data inserted", "An Error occurred", wx.OK | wx.ICON_INFORMATION).ShowModal()
            else:
                dlg = wx.FileDialog(self, "Save as..." , os.getcwd(), filename, "*.*", wx.SAVE | wx.OVERWRITE_PROMPT )
                if dlg.ShowModal() == wx.ID_OK:
                    try:
                        f = codecs.open(os.path.normpath(dlg.GetPath()), "w", "utf-8", "ignore")
                        f.write(codecs.utf_8_decode(codecs.BOM_UTF8)[0])
                        f.write(body)
                        f.close()
                        self.flash._set_FlashVars("data=Succesfully saved text file")
                    except:
                        wx.MessageDialog(self, "%s %s %s" % sys.exc_info(), "An Error occurred", wx.OK | wx.ICON_ERROR).ShowModal()
                        self.flash._set_FlashVars("data=%s %s %s" % sys.exc_info())
        except:
            wx.MessageDialog(self, "Please check data inserted","An Error occurred",wx.OK | wx.ICON_INFORMATION).ShowModal()
            self.flash._set_FlashVars("data=%s %s %s" % sys.exc_info())
#-------------------------------------------
if __name__ == '__main__':
    class TestFrame(wx.Frame):
        def __init__(self):
            wx.Frame.__init__(self, None, -1, "ActiveX -- Flash", size=(640, 480), style=wx.DEFAULT_FRAME_STYLE )
            base = os.path.normpath(os.path.abspath(os.path.dirname(sys.argv[0])))
            swf = os.path.normpath(os.path.join(base, "movie.swf"))
            self.tp = TestPanel(self, base, swf)
    app = wx.PySimpleApp()
    frame = TestFrame()
    frame.Center()
    frame.Show(True)    
    app.MainLoop()

the flash part is really easy. Two text field, one button and one line of code!:

on (click) {	fscommand("saveFile", this._parent.fnome.text + "###" + this._parent.ftesto.text)}

P.S. Moreover today I read in wxPython mailing list a coming new version of wxPython. I hope this will begin to fix varoius problems with Mac installation of SE|PY