Introducing SwfCreator3000
Posted on Tuesday, May 13, 2008 @ 11:55 CET
A friend of mine had a problem where he had a whole bunch of SWFs that were quite similar - the only difference being certain variables and assets, though the library linkage IDs were identical (this is Flash 8 mind you). Now having used MTASC and swfmill before via FlashDevelop, we knew we could place the assets in external SWFs that get compiled in and do some code injection. Since these two are command line tools it also means its scriptable.
So I started hacking together a Perl script that does just that. It had been a while since I'd messed around with Perl but a few hours later I had something that was working but then a long, lazy weekend delayed this post :)
What does it do?
Basically the script loops over a list of SWFs you define in an XML file and compiles them with MTASC, adding in the SWFs that contain your assets and then injecting the variables you've defined. All you need to do is specify the path to the SWF and your classes and the name of your main class that starts up the app. That's it.
Variable injection?
Before each SWF is compiled, SwfCreator modifies your main class a little by adding the variables you've defined to the _global scope. If this sounds dirty to you, I agree and you're right, BUT, to avoid polluting _global we create a single Object - you decide its name - and add all the variables as its properties.
So basically, if the global object name is Cheese, and you have a variable called clickUrl, then you can access it in your code at runtime by calling _global.Cheese.clickUrl.
Having them on _global also makes it easier to test things before you do this for multiple SWFs and then simply commenting out the block.
How do I use it?
First you define your project properties in a file called project.xml (you can always call it something else). This file includes the following:
- a list SWFs that are going to be compiled. You have to define the properties of the file to be created such as the filename, width, height, framerate and Flash version (upto and including 8)
- the path to the SWF containing the assets exported in the library using a linkage ID
- the path to where your classes are located (aka classpath)
- the name of the main class that contains the MTASC entry path that starts up your SWF. If this is new to you, don't worry its simple - check this example over on the MTASC site
- the variables that are to be included
Finally you have to define the name of the object to be created on the _global scope for variable injection, and whether or not to use MTASC in strict mode (on by default).
The sample project.xml file looks like this:
A quick example
Now that you know how it all is put together, you can download the ZIP archive from here. Then:
- extract it somewhere (say the desktop)
- launch Terminal.app (/Applications/Utilities/Terminal.app)
- in the Terminal, change directory to where you extracted it. So for the desktop:
cd Desktop - now we run the script with the example project.xml file like so:
./SwfCreator3000.pl -x example/project.xml
This will build two SWFs and put them in the example/bin folder.
Notes!
This is an alpha version so things might break, if so just let me know. Also this has only been tested on OS X 10.5 (Leopard) with the version of Perl that ships with it (5.8.8, to check run perl -v from the Terminal). Also:
- for some reason the width/height/framerate seem to be ignored by MTASC when you compile in an asset SWF, but the output SWF inherits these from the asset SWF. Using
Stage.scaleMode = "noScale";andStage.align = "TL";can help with this too, and calling adding the dimensions to the SWF name for later reference such as"MySwf_400x200.swf";. - and finally, due to my lack of 1337 regular expression skillz, the
main()MTASC entry point must have the opening brace on the same line and NOT be typed. Sostatic function main() {is fine,static function main():Void(and the opening brace on the next line) is not
Future features
There are a few changes that I can see, for example allowing multiple classpaths, multiple libraries and maybe using swfmill to compile these which might help in letting the width/height/framerate settings stick. In any case, let me know if this helps you out :)
- paulo
PlanetFlash.org
Posted on Monday, April 14, 2008 @ 15:35 CET
Last week at the Flash User Group Norway meetup, Knut showed us one of his latest projects: PlanetFlash.org. So what's Planet Flash - its like MXNA, but its up™ :)
I don't visit MXNA that much simply because lately its often down or simply very slow. Anyhow, the only advantage it has over PlanetFlash is the rating (which shows the click rate), but I can live without that. Normally I live within Bloglines (the Dev:Flash and Dev:Flex folders contain the Flash bloggers I read), but sometimes its nice with something completely different.
That said, there are a few features I'd like:
- The "Blogs" list is cool to show what is being aggregated. However, it would be nice to have a link to the blog and another to the feed. If I see a name I don't recognize I'd like to visit their site instead of stare at some XML :)
- The link to the feed should be correct - for example my feed is at
http://paulofierro.com/rss.xml. Right now it just sends you on to FeedBurner because I like their service but if that changes in the future, I'd lose the people subscribed to the FeedBurner feed. Checking the<link rel="alternate" type="application/rss+xml" />tag in the<head>(which I believe most blogs provide) would get the right URL - It would be nice to able to export the list as OPML
Anyways, just nice-to-haves :) Be sure to check it out and let Knut know if what you think of it.
- paulo
Using FontForge to convert Adobe Type fonts on OS X
Posted on Monday, April 14, 2008 @ 14:34 CET
I've mentioned FontForge before, but never really explained how to use it - its really powerful and I use about 2% of its functionality, a little like how I use Photoshop probably. In any case, this is a quick recipe to converting Adobe Type fonts that have .PFM and .PFB extensions.
First we need to install it, so:
- Check if you have X11 - its under Applications/Utilities. If not, install it - located on your OS X install DVD under Xcode Developer Tools
- Download and install the FontForge package for your flavour of OS X from here. FontForge_intelmacX.4_... for Tiger, FontForge_intelmacX.5_... for Leopard.
Once you have it installed, run X11. Then from the menu select Applications > FontForge. The app starts up, you forgive the interface and find the font you want to open by locating the .PFB file or files (you can select multiple files). Once the font is opened:
- Select File > Generate Fonts
- Select the type of font you want to output. OpenType (CFF) does the job for me, but if you're use them with an app that doesn't support OTF, then TrueType is another way to go
- I turn off "Validate before saving", because there will be warnings, but this is optional
- Hit Save and FontForge will create the font files for you. My usual settings are shown in the image below.
- In the Finder, select all the new fonts and open them at the same time. FontBook is smart enough to recognize the fonts within the same family and install those at the same time which is a nice touch. This means you don't have to handle 20 different windows when installing the font
That's it! Is there a better, more efficient way to do this? Yeah, according to a Linux friend of mine you can run it from the Terminal which means you could script it if you need to convert tons of fonts. But for smaller operations this will work out quite nicely.
Will there be issues with the fonts that are converted? Maybe - I'm no fontographer, but so far this has worked fine for me :)
- paulo
Certified Flex head
Posted on Thursday, April 10, 2008 @ 17:02 CET
On a whim, I took the Adobe Flex 2 certification exam this morning and passed, weee! :)
I've been living in Flex for the past year or so and I'd been thinking about it so I checked out the practice test at the end of the official exam guide last night, and that was the final push. Signed up with PearsonVUE, dropped the $150 (which is not that much now that the dollar is under NOK 5, WTF?) and that was that.
The Java related questions took longer to answer since I only have experience integrating Flex apps with AMF and XML-based services so far, but it was ok all in all. Once you're familiar with a few of the APIs you kinda know the structure of things. So playing with Flex and reading its Bible seemed to be enough, which was the same strategy I followed for the Flash exam two years ago.
One thing I found curious, since English isn't the official language in Norway you get an extra 30 minutes to complete the exam. Tanks!
- paulo
Loading SWFs exported from Illustrator CS3 as MovieClips
Posted on Wednesday, April 09, 2008 @ 14:07 CET
Earlier Chris showed me an issue with Illustrator CS3 I hadn't come across. Basically exporting artwork to SWF for Flash Player 9 works fine, but (unexpectedly, at least for me) the resulting SWF is seen as a AVM1Movie when it gets loaded in to another SWF.
If this is an issue, then this AVM2Loader class should be able to help out. You use it just like the standard Loader class, and it hacks AVM1 movies to AVM2, though apparently there's an issue with audio). Sample code follows:
import net.fladdict.display.AVM2Loader;
var loader:AVM2Loader = new AVM2Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(new URLRequest("art.swf"));
addChild(loader);
function onLoaded(event:Event):void {
var info:LoaderInfo = event.target as LoaderInfo;
trace(info.content);
}
There is one little gotcha when exporting as a SWF in Illustrator. You have to use the "File > Save for Web & Devices" dialog. There you have to pick SWF as the format, Flash Player 9 as the output type and then either "AI File to SWF File" or "Layers to SWF Frames". Both work fine and trace out [object MovieClip] once loaded in.
What doesn't work for some reason is using "File > Export" and choosing SWF as the format and Flash Player 9 as the output type. Loading a SWF exported in this manner always traces out [object AVM1Movie]. Weird.
- paulo
Removing .SVN folders in OS X with Automator
Posted on Monday, April 07, 2008 @ 13:54 CET
Occasionally I come across some excellent ActionScript libraries that I download to play with (for example Papervision and Degrafa) from their respective Subversion directories. If they seem useful (like the mentioned examples which are both super sweet in their own right) I add them to our Subversion repository, but before I do that I need to remove all the .svn folders which are present in each and every folder.
Not a fan of doing this by hand I looked for a way of automating it. Now if you're comfortable in the Terminal, all you need to do is navigate to the top directory and run the following command which will remove all .svn folders recursively:
find . -type d -name ".svn" -exec rm -rf \{\} \;
Now if the Terminal is not your thing, or you want a way to integrate this with the Finder then the Automator is your friend. Simply fire up Automator and choose a Custom workflow. Then make a workflow that looks like so:
Then save it as a plugin for the Finder (File > Save as Plugin) and give it a name. Now all you have to do is right-click on the folder containing the nested .svn folers and select More > Automator > Remove .SVN Folders.
If you don't want to make it yourself, you can download the workflow here. Unzip it and within your home directory, move it to Library > Workflows > Applications > Finder. You might have to logout and login (or relaunch the Finder) for it to appear.
- paulo
My list of OS X tools and utilities I couldn't live without
Posted on Thursday, April 03, 2008 @ 12:25 CET
It seems like everyone around me is switching to Macs (5 friends in the past two weeks) and the questions naturally arise about what apps one needs, and what is the OS X replacement for insert-Windows-app-here. Here's my list of third-party apps and utilities I couldn't live without:
- Transmit - hands-down the best FTP app out there
- Quicksilver - app launcher and sooo much more (if you spend 5 mins and read the docs)
- SMCFan - control default fan speeds (for older models, if you want to disable egg-frying mode)
- Xtorrent - its like iTunes for torrents (legal ones of course)
- Adium - IM client that supports all networks (MSN, GTalk, AIM, Yahoo! etc)
- Textmate - hands-down the best text editor out there
- NeoOffice - OpenOffice built for Mac
- Camino - FireFox clone for Mac (without all the crashes, but sadly also the extensions :)
- UnrarX - RAR utility
- Fugu - SSH/SCP client
- SCPlugin - SubVersion client that integrates with the Finder (configuration help here)
- Connect 360 - Xbox360 media center
- MediaLink - PS3 media center
- VLC - universal media player. Plays nearly anything you throw at it
- Perian - codecs for divx/xvid, ac3, flv, etc
- Flip4Mac - lets you play back Windows Media files
- MenuCalendarClock - clock replacement with calendar + week numbers
- AppZapper - application uninstaller
- MousePosé - presentation helper
- ScreenFlow - hands-down the best screen capturing app
- OmniOutliner - fantastic outliner
- OmniFocus - fantastic task manager
- Skype - um, its Skype (integrates with the Address Book too)
- Deeper - configuration utility
- FBCal - FaceBook birthdays + events calendar for iCal
- FlickrExport - Flickr Exporter for iPhoto
- Twitterriffic - Twitter client
There's probably one or two that I missed but I think that covers most bases.
Now here's a few gems that ship with OS X:
- Dictionary - dictionary, thesaurus and wikipedia in a single app. Hover over a word anywhere and hit Control+Command+D to look it up
- Preview - preview any file (nearly) instantly. Finally open up those PDFs without waiting an hour :) In Leopard, hit Space to preview it using QuickLook
- FontBook - a font manager that works (unlike its Windows'control panel counterpart)
- DigitalColor Meter - utility to get the colour of any pixel on the screen (Shift+Command+H to hold a colour)
- Keychain Access - global password manager for all apps (that bother to integrate with it. Looking at you FireFox)
When (not if) apps freeze, you need to force quit them. To do the Ctrl+Alt+Delete tango you can either:
- right-click on the app's icon in the dock and hold down the Option (Alt) key, then select Force Quit, or
- press Command+Option+Esc and selec the app from the list
Keyboard combos for taking screenshots (they appear as PNGs on the destkop):
- Whole Screen - Command+Shift+3
- Certain Area - Command+Shift+4 (drag a box)
- Specific window - Command+Shift+4, then hit Space and pick your window
Perhaps not as intuitive as the "Print Screen" key, but far more better. And finally a comprehensive list for all keyboard fanatics.
- paulo
South Park is free
Posted on Wednesday, March 26, 2008 @ 12:24 CET
I love South Park, everything about it and its creators Matt Stone and Trey Parker. Its always hilarious, always brilliant.
Once again they show off their genius and, showing that at least Comedy Central gets it, you can now watch ANY South Park episode whenever you want to at South Park Studios, simply goto the "Full Episodes" section. That's 12 seasons of episodes available at pretty good quality with only a few ads tossed in. Sweet!
Like Michael Arrington from TechCrunch writes:
Instead of fighting BitTorrent and sites like Allsp, South Park creators Matt Stone and Trey Parker are simply going to try to make them irrelevant by offering something better.Hopefully someone out there in Hollywood-land is watching and learning from this. Over on the NRKbeta blog they coined the NRKbeta doctrine:
The only way to control your content is to be the best provider of it.Well put.
- paulo
Cairngorm and AMF:PHP - bending Services to work with NetConnection
Posted on Thursday, March 06, 2008 @ 16:22 CET
At work I've been getting into Cairngorm for a little while now and its quite a beast to tackle. It took me three attempts to actually grok what was going on, and although the article on DevNet is great and the examples I found are good (the image helps) until you actually play with it you might be as lost as I was.
The biggest problem was setting up the business services. The Cairngorm Store example uses <mx:RemoteObject /> tags that tie in to the ServiceLocator. However, those have to be defined in services-config.xml and the endpoints are hard-coded and baked in (unless you do some Ant magic). That's something I didn't want to do, and also I'm using NetConnection to talk to AMFPHP.
So what I ended up doing was rolling out a business Services class as a Singleton class (instead of an MXML) with a single NetConnection object, instead of one per service. I don't think this matters since every business Delegate has to know the remote method name anyway and I find its better to keep all that stuff within the Delegate. That way the Services class knows about the endpoint and encoding type, and the Delegates know what they're calling.
The second change is within the Delegates. Instead of defining service as an Object, I define it as a NetConnection object. Also, the Delegate constructor receives an IResponder object to use as a responder. The problem is this is a mx.rpc.IResponder object, and NetConnection only plays with flash.net.Responders. However, they are pretty much identical so instead of doing like so:
public function getProducts() : void {
var call : Object = service.getProducts();
call.addResponder( responder );
}
I do like so, simply creating references to the IResponder object's methods:
public function getProducts():void {
var r:Responder = new Responder(responder.result, responder.fault);
// service is a reference to the connection within the Services class
service.call("getProducts", r);
}
So the main concepts and ideas behind Cairngorm remain intact (I believe). I'm still a n00b when it comes to the microarchitecture so there might be something I missed, but this is working great for me for now :)
- paulo
Cutting the tight rope - getting rid of Acrobat as the default PDF viewer on OS X
Posted on Wednesday, March 05, 2008 @ 14:20 CET
After installing CS3 the second most annoying piece of Adobe software (the first being the all-might Updater, which seems to have become sentient), Acrobat decided to take over. If I needed to author, comment, annotate or do anything with PDF files other than just view them I might think otherwise, but I don't so I don't. Compared to Preview.app, Acrobat is a slow mofo that somehow decided to become my default PDF viewer.
Fixing this in the Finder is easy enough, right-click file > Get Info > Open with > select Preview > Change All and you're done. But what about Safari? Clicking on a link to a PDF takes me to a blank page where I'm then asked for a program to use to view the PDF. Selecting Acrobat saves that preference but there's still a 20 second wait every time you attempt to view a PDF, not the speedy response you become used to when using Preview.
Luckily getting rid of Acrobat as the default viewer in Safari is as easy as 1-2-3:
- Close Safari
- In the Finder, go to /Library/Internet Plug-Ins/
- Delete AdobePDFViewer.plugin
Now empty the Trash to make sure that sucka doesn't come back :)
- paulo





