In development: flashticle
We at Mochi Media have been working on Macromedia Flash related stuff a lot lately (especially MochiBot). One such thing is a soon-to-be-released (but available from svn) open source library called flashticle.
flashticle deals in all of those gnarly binary proprietary formats: FLV, SWF, AMF, Flash Remoting, Local Shared Object files, etc. The only reason this was possible is because of the efforts of the osflash community, who have tirelessly reverse engineered all of these things and boiled it down into source code and documentation that I can learn from.
One of the more interesting features of flashticle is the integration it has with TurboGears: flashticle.turbogateway. This lets you very simply develop Flash Remoting services using Python. How simple you ask? Well, here's the Python source to TWO demo applications:
- turbogatewaydemos.model (database model for both)
- turbogatewaydemos.services.PizzaService (pizzaService example from AMFPHP / ARP)
- turbogatewaydemos.services.BirthdayOrganizer (BirthdayOrganizer example from OpenAMF / ARP)
This is a total of a whopping 117 lines of very liberally spaced Python code that defines all three database tables and fully implements every feature of both sample applications.
The PHP version of the pizzaService backend (pizzaService.php) is 138 lines of code, is one big security flaw (doesn't escape SQL properly, big surprise), is MySQL specific, and it doesn't include the DB schema and can't create any tables for you (thank you tg-admin sql create).
The Java version of the BirthdayOrganizer backend, which I won't even bother linking to, is well... ginormous. 246 lines of XML configuration sludge in 5 files, 29 lines of SQL schema in 1 file, and 3004 lines of Java code in 45 files. Holy crap. If you add that all up, the trivial BirthdayOrganizer example is only a hair shorter than all of flashticle! And the BirthdayOrganizer example builds on top of 15 Java dependencies and requires a J2EE server plus ant. Friends don't let friends code Java. Oh, and it's also MySQL specific, but you better be damn well sure that there's a stub implementation you can subclass and an XML file you can mangle in order to support something else if you so choose to write that 200 lines of code to support a single three column table database.
Where can I learn more about Flashticle? Specifically why can it do for me as a web developer? What will it add to a website?
(unrelated, are you the maker of py2app? If so is there any way you could make a version that works on Windows? My situation is that I don’t have a mac but I want to make an app of a program for mac users. Any advice?)
Thanks,
Greg
Comment by Greg — 2006-01-07 @ 10:50 am
If you don’t already know what it does, it’s not for you. Not yet, probably never.
Yes, I wrote py2app, and I have no plans of making it operate on Windows. It’d be hard, and I have better things to do.
Comment by bob — 2006-01-07 @ 10:53 am
Honestly I’m a little fuzzy on what it’s for too. But I refuse to believe it’s not for me. Everything is for me. Feed me!
Comment by Ian Bicking — 2006-01-07 @ 11:04 am
Follow the links, google the terms you don’t understand. How hard is that? :) Understanding all this stuff myself, I have no idea what’s fuzzy to you.
Comment by bob — 2006-01-07 @ 11:09 am
Am I the only one that thinks the name is a tad dodgy? May I enquire as to its derivation? ;)
Comment by Moof — 2006-01-07 @ 12:09 pm
There are several possible derivations, I’m not going to claim anything in particular.
Comment by bob — 2006-01-07 @ 1:18 pm
This is very cool! I ended up choosing Flash Remoting with AMFPHP for a project I’m involved in. In the future I thought it would be fun to combine Turbogears with FLAP (http://www.simonf.com/flap/) to give a Flash interface to a pre-existing Python program. I am very glad you came up with a solution so quickly, and that integrates well with Turbogears. I will use this in the future very soon.
Although Flash is riddled with proprietary formats, I think the technology is way more slick than any AJAX application can come close to. Not having to worry about browser compatibility is HUGE plus. I recommend people give it shot. It does work with Flash Player 6 and up. I think AMFPHP (http://www.amfphp.com/ http://www.amfphp.com/wiki/) has the most understandable examples.
Thank you for your work
Kevin Deenanauth
Comment by Kevin Deenanauth — 2006-01-07 @ 6:03 pm
SMX would probably as few lines as python, or fewer.
Comment by doc — 2006-01-07 @ 6:54 pm
Kevin:
Flash is expensive and doesn’t generally cater to a very good UI for most web apps. The way it deals with text and the fact it’s constrained to a rectangle is just bogus in a lot of cases. However, for things that you can’t reasonably do in HTML, it’s the only game in town. Not having to worry about browser compatibility is indeed a huge bonus.
doc:
SMX would be 0 lines of code, because it’s not capable of doing Flash Remoting or funky binary formats. Way to RTFA buddy.
Comment by bob — 2006-01-07 @ 7:42 pm
You seem rather hostile to the genuinely interested commentators to this entry.
Comment by Astro — 2006-01-08 @ 1:14 am
Bob’s a pretty brave dude. Takes a lot of guts to try to apply CS best practices to JS and AS. But geeze, it’s a shame he’s wasting his talent trying to drag these brain-dead environments into the modern era when he could be advancing the state of the art.
Comment by some geek — 2006-01-08 @ 7:23 am
Re: py2app for windows, uh, don’t you want:
http://www.py2exe.org/
Comment by Jeremy Dunck — 2006-01-08 @ 9:36 am
Thanks for the links! I learn Python and have just been looking for some examples! Thanks again!
Comment by Nataly — 2006-01-09 @ 8:12 am
Fantastic. Thrilled. Especially since I just got done writing a search interface in Python using MySQLdb and am loathe to re-write it in PHP, let alone get AMFPHP installed on my web host’s server.
On that subject, what will installing Flashticle involve? I am using a webhosting company and don’t have admin access on the server. I am a newbie with Python, but I love it already and did manage to get my webhosting folks to at least ‘install’ MySQLdb and pickle (actually I think pickle was standard)…
If you’re feeling very friendly, how about a really dumb question… how do I go about downloading the SVN trunk? Via a web browser, I of course get the directory view… of course, I probably don’t need to be downloading anything if I can oblige my webhost into doing it.
Thanks a million.
Comment by Matthew — 2006-01-09 @ 1:06 pm
Astro,
I don’t have time for people who can’t be bothered to use google or click on links.
Matthew,
You’re right, pickle is standard. It’s actually possible to install Python modules without administrator access. In order to use flashticle you’ll need Python 2.4 or later. If your web host has that, you’re probably ok. If you’re interested in installing flashticle, check out the Easy Install wiki: http://peak.telecommunity.com/DevCenter/EasyInstall
Comment by bob — 2006-01-09 @ 3:02 pm
Jeremy,
No, he wants something to create Mac applications, but he wants it to run on Windows. Basically a cross-compiler.
Comment by Jim — 2006-01-09 @ 5:22 pm
Bob - Just a note - the css for the blog makes flashticle look like flashtide - the c and l tend to blur. flashtide sounds so web2.d’oh
Matthew - to download things from subversion, you’ll need a subversion client. i prefer using the actual svn client ( http://subversion.tigris.org ), but there are os specific ones that run off the GUIs. For more info, you should refer to the svn book : http://svnbook.red-bean.com/
Comment by Jon — 2006-01-10 @ 11:54 am
Hi Bob,
Very cool stuff! Great to see a Python implementation. You’re right about the Java backend for the Birthday sample, btw. It is in no way meant to be a reference and I hope to include a much lighter sample in a future release of Arp. By the way, I’m focussing on a single app that will be the reference for Flash/AS2, Flex 1.5, Flex 2/AS3, AS3-only and it looks like it will be the Pizza Service. I look forward to including a Flashticle version too.
Comment by Aral Balkan — 2006-02-09 @ 6:32 am
Hi Bob,
I’m still just getting my head around some of these topics (i.e. object serialization), and I have a question that might clear things up: what is the difference between using Flashticle/Flash Remoting and using simplejson and then decoding the stringified object in ActionScript using JSON for AS? I guess the fundamental difference is that with Flashticle you can actually make remote procedure calls that are implemented in a Python module on the server, whereas in the other (JSON) approach, in Flash you are still just running a Python script on the server with some parameters and receiving back a stringified response?
“The right tool for the right purpose.” What ‘purposes’ call for Flashticle vs. simplejson?
That might not make any sense… Thanks again for the hard work and insight.
Matthew
Comment by Matthew — 2006-02-10 @ 10:20 am
AMF is a compact binary serialization format built-in to the Flash VM. It’s fast (at least on the client) and it gives you a lot of behavior for free. You’d use flash remoting over JSON or XML with Flash for the same reason you’d use JSON over XML with JavaScript: simplicity and speed.
Comment by bob — 2006-02-10 @ 11:04 am
Cool! Mentioned this on my blog here:
http://noisetheatre.blogspot.com/2006/02/firefox-python.html
Comment by robin — 2006-02-24 @ 1:03 pm
Bob,
Can you show me what the URL would look like to call PizzaService.getOrderList? To the point, what would the URL look like to set up the service to PizzaService in ActionScript?
Would this work?
NetServices.setDefaultGatewayURL(”http://www.bobswebsite.com/PizzaService.py”);
this.Conn = NetServices.createGatewayConnection();
this.Conn.getService(”getOrderList”,this)
…
Thanks for your help! I think once I have an answer to this I’ll be good to go (I am still setting up my webserver so I can’t quite test it myself yet)…
Matt
Comment by Matthew — 2006-03-18 @ 1:18 pm
The gateway URL is whatever you make it in the controller. The example’s URL is /gateway, similar to the other implementations. Read the code, it’s all there.
Comment by bob — 2006-03-19 @ 5:17 pm
Been reading lots of code, have learned a lot, but in the grand finale I’m now getting “Error opening URL: http://www.stormpulse.com:8080/gateway” in Flash. Also happens when I try ending the URL with a forward-slash, which I know differs from your example.
If I visit http://www.stormpulse.com:8080/gateway in my browser I get “Bad Request”. But I *can* visit gateway/servicename/method/args, etc., and I can get back results (actually depending on the return type I get stacktrace error about joining/iterating on a chunk). Visiting http://www.stormpulse.com:8080/gateway/ (notice the trailing forward-slash) also works, returning “Build time: 0.003s, Page size: 0.00KB”.
If I change my AS to point to “http://examples.macromedia.com/flashservices/gateway”, for example, I don’t get the error.
I’ve studied and compared your examples to my code, but I’m a little stuck. Does any of this seem suspicious given all your experience?
I realize this is basically asking for free help, but I don’t know anyone else to ask. Thanks a million (you’re my only hope…).
Comment by Matthew — 2006-04-13 @ 4:30 am
I thought this might help . . . my controllers.py file:
import pkg_resources
pkg_resources.require(”flashticle[turbogateway]“)
import os
import turbogears
from turbogears import controllers
from flashticle.turbogateway import FlashRemotingGateway
class Root(controllers.RootController):
def __init__(self):
self.gateway = Gateway()
@turbogears.expose()
def index(self):
dirname = pkg_resources.resource_filename(__name__, ’static/examples’)
join = os.path.join
pagenames = sorted(
fn for fn in os.listdir(dirname)
if not fn.startswith(’.') and os.path.isdr(join(dirname,fn))
)
return dict(pagenames=pagenames)
class Gateway(FlashRemotingGateway):
def __getattr__(self, name):
# automagically load anything in the services dir
if name.startswith(’_') or ‘.’ in name or ‘/’ in name:
raise AttributeError
m = __import__(”stormpulse.services.” + name, globals(), locals(), ['services'])
return getattr(m, name)()
Comment by Matthew — 2006-04-13 @ 4:33 am
I’m not interested in the Remoting features but would like to know that the capabilities related to FLV are? A short reply would be appreciated.
S
Comment by Stefan Richter — 2006-11-27 @ 6:09 am
Am I the only one that pulls up a link to pornography when I follow the OpenAMF (http://www.openamf.org) link in this line?:
turbogatewaydemos.services.BirthdayOrganizer (BirthdayOrganizer example from OpenAMF / ARP)
Maybe it demonstrates the BirthdayOrganizer, I don’t know, I quickly left the site. If so maybe some kind of ‘Not Safe for Work’ warning would be good.
Comment by Rob — 2006-12-12 @ 6:58 am
Probably. I see a RedHat test page. I’m guessing their server was hacked.
Comment by bob — 2006-12-12 @ 10:39 am
Hi I installed flashticle and all the associated dependencies.. I get the following error when I try to access amf.. Would you know the reason..
[root@sahana flashticle]# python
Python 2.4.2 (#2, Dec 23 2006, 00:52:43)
[GCC 4.0.0 20050519 (Red Hat 4.0.0-8)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import flashticle
>>> import flashticle.amf
Traceback (most recent call last):
File “”, line 1, in ?
File “build/bdist.linux-i686/egg/flashticle/amf.py”, line 305, in ?
File “build/bdist.linux-i686/egg/dispatch/functions.py”, line 690, in when
File “build/bdist.linux-i686/egg/dispatch/functions.py”, line 577, in _decorate
File “”, line 10, in parseRule
File “build/bdist.linux-i686/egg/dispatch/functions.py”, line 440, in parseRule
File “build/bdist.linux-i686/egg/dispatch/functions.py”, line 326, in parse
File “build/bdist.linux-i686/egg/dispatch/ast_builder.py”, line 383, in parse_expr
File “build/bdist.linux-i686/egg/dispatch/ast_builder.py”, line 378, in build
File “build/bdist.linux-i686/egg/dispatch/ast_builder.py”, line 178, in power
File “build/bdist.linux-i686/egg/dispatch/ast_builder.py”, line 284, in com_call_function
File “build/bdist.linux-i686/egg/dispatch/predicates.py”, line 547, in method
File “”, line 5, in expressionSignature
File “build/bdist.linux-i686/egg/dispatch/predicates.py”, line 721, in convertIsInstanceToClassCriterion
File “build/bdist.linux-i686/egg/protocols/interfaces.py”, line 298, in __call__
File “_speedups.pyx”, line 198, in _speedups.Protocol__call__
File “_speedups.pyx”, line 183, in _speedups._adapt
protocols.adapters.AdaptationFailure: (”Can’t adapt”, , )
Comment by Sharmila — 2007-01-08 @ 3:26 am
Works fine here with Python 2.4.4 on Mac OS X x86. I don’t know what it doesn’t work for you, but it doesn’t have anything to do with flashticle specifically. Looks like a botched installation of RuleDispatch or something.
Comment by bob — 2007-01-10 @ 8:57 am
Bob,
Has development ceased for this project?
Thanks,
Chris
Comment by Chris — 2007-02-28 @ 11:25 am
No, we use it in production. I’m not working on the remoting stuff, and I don’t really have the time or interest to do a release any time soon… but the project isn’t going anywhere.
Comment by bob — 2007-03-01 @ 7:58 pm