Flash against the world

Although I use to make a living from Flash since Flash 4 (learning time) and Flash 5 (real usage time, when AS 1 was born), I’ve never been in the mood to write about the goods and chimes of Flash, as most of times I’ve been forced to agree with the general sense which said that stuff made-in-Flash was crap. Who doesn’t hate Flash intros and banners and nonsensycal fireworks?

Today, in the mature age of Flash (and maybe myself’s professional mature age), I see the cake quite different.

  1. Flash is a plugin, just like the old Java plugin, QuickTime, Windows Media Player or VRML: a way to introduce rich content in a browser.
  2. Nobody demands for a plugin a bunch of features regarding navigability (integration with common browser’s features, such as history, bookmarking or accessibility), except for the Flash plugin.
  3. People in Macromedia (then) and Adobe (now) made a great effort of creativity and enthusiasm in order to introduce in the Flash plugin lots of features, including support for audio, video and 3D. Do you remember when you was forced to install a bunch of things only to hear audio in the mp3 format? Flash supported it. Do you remember when watching a video in the web was sort of chance if you had the codec installed, if available at all for your machine specs? Flash made possible a successful website such as Youtube. Do you remember when people needed something else, from the programming point of view, and AS 2 was born (and yet more AS 3), being a real alternative to today’s so called Web 2.0 and smelly things such as Ajax, which is today a very common technology?
  4. Flash, even being a plugin, offered a bridge to the user’s surfing experience from the beginnings. Wheter you like it or not, being more or less difficult for the developer, you can bookmark a page from Flash contents, access the history, make a Flash movie fully accessible and localizable, make practice of asynchronous communication with the server, get your contents indexed by major search engines and a long catalogue of things you would never expect from a plugin.
  5. Most probably, people who feels anger against Flash, feels anger as well against bad (or low-cost, if you prefer so) web developers. Me and my team can make a full blown rich app driven by Flash -in the client side- in a few days, supporting navigability, accessibility AAA and advanced features (such as databases in the backend). Today, 2010, you are told to make a website with A/V support. You have three days to make it live. Will you rely on WM, QT or Real? Or you will stick with the de-facto standard, codenamed Flash? What about 3D? Do you prefer Flash via Swift 3D, for example, or you will force your users to install whatever plugin?
  6. Bad and low-cost developers still can offer with Flash to their bad and low-cost customers much more than they can offer with their bad and low-cost web knowledge.
  7. Although Flash still offers usually much more features than other plugins (I won’t say “similar plugins”, as I don’t know similar ones), including a brand new OOP programming interface with AS 3 and integration with most if not all of modern technologies, along with the mentioned A/V capabilities, as well as support for 3D, bitmap and vector graphics, camera and micro input, etc… Although Flash offers more and still more, it still offers more again: Flash was exiled from major mobile platforms (specially iPhone, which is a point of reference), but Flash keeps trying and trying. The new betas, with an eye put over the mobile platforms, are performing so fine in the desktop in the first optimization. I believe they’ll keep improving. Stuff in the computer uses to require more and more resources (RAM, CPU, etc.). That’s because we all are forced to replace our computers, mobile phones (and now also TVs —in Spain, at least— with digital TV). And now Flash is in the business of downsampling: more features, less resources. It was time, anyway, and now begun the race. They’ll keep improving. Once more again, we demand from Flash a very high level of performance and optimization we don’t in fact demand to the own machines (nobody seems to blame Apple for creating a 4 GB iPhone or iPod, then very soon the 8GB one, then 16, 32GB, etc., making every new release feel oldies the previous ones). Adobe is making his homework in order to optimize CPU and RAM usage, support multitouch and a very long etcetera in the chain of the —oftenly stupid— needs of the market.
  8. SWF specs are free. We have now many tools —paid and free— to create and compile Flash movies. If you are freak enough, you can even create your own swf-based format and your swf-based flash player. In fact, they DO exist. You can even use your Flash knowledge to create robust cross-platform desktop apps based on SWF (Adobe’s AIR wasn’t the first to make it real, others did it first, creating environments similar to the RealBASIC or Revolution IDE’s and runtimes, such as mProjector, Zinc or the open-source HippoHX… And much more).
  9. Still waiting for others’ answers: universal, cross-platform, localizable, accessible, extensible and with the unlimited level of support of a huge and still-growing community of developers. And, as stated, with the enthusiasm required to make something new every day.
  10. Finally, the market rules. In my personal and tiny market, I never thought I was forced to learn AS 3, coming from AS 1 and 2, as well as I never thought the print shop would never accept as input a 5MB PDF document, instead of a Quark 3 document with a bunch of fonts and images enclosed in a ZIP disk. Today we have market for Flash, as well as yesterday, and a brighting future for the “newborn” AS 3 language, along with all the daily newcome features for us developers and end-users.

Run command-line from JSFL

This is a somewhat old topic born with the original FLfile library by Guy Watson: the undocumented runCommandLine JSFL command, which still exists in FLfile. Previously we had FLappleScript, but it stopped working some time before runCommandLine was available for us in the Mac (IIRC).

If you are new to this, you may be shocked when you type and run this in a new “Flash JavaScript File” document:

FLfile.runCommandLine("echo 'ok' > /tmp/sample.txt;open /tmp/sample.txt");
// works in Mac, use your windows' shell knowledge if you use Win

Or this one:

FLfile.runCommandLine("osascript -e 'tell app \"iTunes\" to playpause'");

These are stupid examples, but I have a couple of interesting projects using a mix of various technologies, including JSFL and Flash, AppleScript, the shell and Illustrator, etc., which is a very promiscuous mode of scripting, but very funny and inedited for many people.

This command only returns (I think) the exit status (1 or 0), but still there is a bunch of ways to get your data (such as writing it to tmp files and reading them from JSFL using FLfile.read())

WindowSWF, mix ActionScript and JSFL for automation and productivity

It’s a long title for a post which could, in fact, be the only message without extra ellaboration. But I’ll ellaborate a bit, because I think this is a underrated feature I love in Flash, which allows to the end-user a full experience of automation and high detail customization of the Flash IDE. This post is for those of you who don’t know about it.

You can create a UI in Flash/ActionScript, link it with JSFL (Javascript Flash, a javascript-based language to drive the Flash IDE) and create your own utilities panel with customized solutions for your daily work. Such as this:


I use every day the buttons in this panel. The first button in the top-left corner, for example, will convert selected items in the stage to named movie clips. It’s a silly task, but some times, before I worked out this solution, I was forced to do it manually hundreds of times in a single day (!) –> select, F8, insert name for symbol, insert name for instance in the stage.

My most impressive automation task was one responsible of arranging, making certains changes and publishing thousands of FLA files in a row, which reduced various workdays to 20 or 30 minutes I could spend in a delicious capuccino while the machine was working by itself.

This isn’t a guide, so I’ll describe briefly the mechanism:

1. You have some need (usually automation of repetitive tasks in the Flash IDE).
2. You write a JSFL command in order to replicate what you use to do manually –> most of times *any* task can be duplicated via JSFL. If you don’t believe it, create a new document, make a rectangle, group it, then go to the menu Window > Other Panels > History. Everything listed in there is pure JSFL recorded which you can copy to the clipboard. More complex tasks will require heavy tweaks, though 😉
3. You create a FLA file with a button (or buttons, progress bars or whatever) linking to the JSFL command. Usually, JSFL commands are stored in the “Commands” folder of Flash’ main configuration dir and can be accesed as well from the Commands menu. You can even assign them a shortcut. But sometimes you run out of shortcuts or you can’t remember more shortcuts (!). This is the time when you need to create your own toolbar with that bunch of customized daily tasks. You call the JSFL command from ActionScript as follow:

	MMExecute('fl.runScript(fl.configURI + "Commands/selec-to-movies.jsfl");');

This example is using AS 2 syntax, but that isn’t a problem, very simple to port it to AS 3. Basically, you call the ActionScript method of the same name, which executes JSFL code. This method is *only* available to “WindowSWF” panels, XMLtoUI dialogs (created on the fly usually by JSFL commands, that is another topic) or UI components. Obviously, no sense out of the Adobe Flash IDE.
4. Move the resulting SWF file to the WindowSWF folder of the config folder (next to Commands, Components, etc.).
5. Relaunch Flash. Now you can access your brand new panel from the menu Window > Other Panels, and it will behave just like any other utilities panel (more or less, you will learn some tiny details when you do it real).

And that’s all. Even if you don’t write your own JSFL solutions, you can still create a WindowSWF panel and link it to others’ JSFL commands you can find in Adobe’s Exchange web site.

Collaborative development and flow diagrams

I find very useful working with flow diagrams when in the middle of complex development systems and it’s absolutely a must-have when you are part of a team. Nobody can access your mind, so nobody can be sure about your thots and the internal flow diagrams running and changing continuously in your brain. So, a flow diagram with read/write access is a great feature for all developers working together in the same cake.

flow diagram

Appart from that, you will find many times, when working in the graph, that you are missing something you must implement, something you forgot when you were in UI-mode fighting against fonts and colors.

That’s the difference between conceptual and abstract design.

Flash movie overlapping other layers fix

Some times, you need something to overlap (that is, display over) a Flash movie, and seems Flash doesn’t like that. By default. But you can use the parameter “wmode” to change this float-above-all behaviour (which, BTW, doesn’t show the same in all the browsers). The default “wmode”, if not specified, is window. We want it to be opaque or transparent (if transparent, the flash movie won’t have a solid background and you will see whatever is below the flash movie). Of course, the layer which will overlap the Flash movie, must be in a z-index higher than the own Flash movie.

I know this is easy, but there are lots of controversial in the web regarding this topic, so I thought I should clarify it, and also keep this info in this blog for future self-consumption.

This article explains it all in detail and includes examples for all “wmode”s: http://www.communitymx.com/content/article.cfm?cid=e5141

AppleScript to convert HTML to PDF via Smile

This has been allways a tricky thing (convert a web page to PDF, preserving the more info possible, including text and clickable links), but since Smile 3.2 is a one-liner I thought I should share (specially when I didn’t find examples for the pageloaded event). This will save a “random” web page to your desktop, in a file called “file.pdf”. If you wanna see it in action, just remove “visible:false”:

script callback
	on pageloaded w
		save w in "~/Desktop/file.pdf"
		beep 2
		close w
	end pageloaded
end script

set webPage to "http://www.qilania.com/"

make new web window with properties ¬
	{path name:webPage, script:callback, visible:false}

It won’t preserve properly the formatting of certain web pages or embedded plug-ins contents, so if you need the screenshot for aesthetic purposes, Smile also provides a command called take screenshot, which will make a image of the rendered page (use it instead of “save w” as “take screenshot of w in …”). You may first resize the window to your favorite size, as the screenshot will only contain the visible area of the web window, but that is left as an exercice for the reader 😉

Very useful code for many tasks (web related), specially if Smile is your main script editor.

AppleScript to count pages of PDF documents via Skim

I found Skim to be the perfect replacement for Preview (ie, a fast app to review PDF documents with notes, etc.). And it also provides a decent AppleScript dictionary, so it’s also the perfect app to make one of those great time-savers. Follows sample code you can save as a droplet (and process a bunch of PDF files via drag & drop) or as a compiled script to be run from any script launcher:

open (get selection of application "Finder")

on open pdflst
	set cnt to 0
	repeat with i from 1 to count pdflst
		--> just in case comes from run handler...
		tell application "Finder" to set pdfFile to (pdflst's item i as alias)
		tell application "Skim"
			open pdfFile
			set cnt to cnt + (page count of (get info of document 1))
			close document 1 saving no
		end tell
	end repeat
	display dialog ("" & cnt & " pages for " & (count pdflst) & " documents...") with icon note
end open

I know it’s trivial code, but still you must spend some time to find a solution for your PDF-page-count needs, and this is a fast and free one.