Better Flash Asset Loading using SWCs

June 8th, 2009

One problem with Flash development recently is the disconnect between assets created in the Flash IDE and code written in the code editor (Flex Builder, Flash Develop, FDT etc). The code editor has no knowledge of the FLA, so there is no way to list the FLA's exported symbol linkage ids or the names of movieclips within a symbol instance (sub-clips). This can lead to lots of back and forth between Flash and the code editor, tracking down missing or misnamed symbols and sub-clips.

For AS projects, Flash assets are typically loaded by using 'Embed' metatags, using 'getDefinitionByName' or using something like Grant Skinner's FlashLib. I recently found out about an alternative method via a comment on Ian Lobb's blog, which is to use SWCs.

It turns out that using SWCs solves the above issues for very little extra setup. Using SWCs means the compiler knows about the FLA and gives code completion on symbol names and sub-clips. Anytime the compiler knows about stuff, it's going to save you debugging time by flagging errors before they happen. Symbols also retain their timeline ActionScript (unlike using Embed tags).

Example usage:

Actionscript:
  1. //import symbol from FLA
  2. import assets.MySymbol1;
  3. ...
  4. //Instantiate symbol instance               
  5. var clip:MySymbol1 = new MySymbol1();
  6. //access symbol's sub-clip properties
  7. clip.mcGreen.alpha = 0.5;

Example Flex Builder code completion:

SWC Symbols

SWC subclips

Where this technique gets really interesting is with Flash Builder 4's Package Explorer. This allows you to browse inside a SWC and view all exported symbols and sub-clips.

package explorer

This technique can be used with any smart AS editor. The set-by-step for Flash Develop is here. For Flex Builder you want to do something like this:

  1. In Flex Builder, create a new AS project.
  2. In the project folder create a new FLA: 'assets/assets.fla'.
  3. In the Flash publish settings, check 'Export SWC'.
  4. Create a symbol in the FLA. Set the Linkage id to: 'assets.MySymbol'.
  5. Publish the SWC.
  6. In Flex Builder do Project -> Properties-> ActionScript Build Path -> Library Path -> Add SWC. Enter the path to the SWC ('assets/assets.swc') .
  7. In Flex Builder, edit the main class. Type 'import assets.'. The symbol name you defined in the FLA will now show as a code completion option.

Anyone know of any disadvantages of using this method?

Error Message of Doom: “Page XXX of your document has been damaged. You should delete it.”

June 2nd, 2009

Damaged SymbolThis error caused us some stress at the last minute before a site launch. When doing 'Save and Compact' or 'Save As...' on an FLA, Flash IDE gives a bunch of the following errors: "Page XXX of your document has been damaged. You should delete it."

The solution turned out to be simple. Copy all the library symbols from the damaged FLA into a new document. Error goes away. As far as we could tell, this was caused by sharing files between Flash version 10 and 10.0.2. Moral of the story - get the Flash update now.

Another Reason to Love TweenLite

May 30th, 2009

I just found a useful function in the TweenLite library, which is great for easily sequencing multiple function calls. To call myFunction() in half a second with param1 and param2, do this:

Actionscript:
  1. TweenLite.delayedCall(0.5, myFunction, [param1,param2]);

which is a lot less code than:

Actionscript:
  1. var tmr:Timer = new Timer(500, 1);
  2. tmr.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerEvent);
  3. tmr.start();
  4. private function onTimerEvent(event:Event):void{
  5.     myFunction(param1,param2);
  6. }

TweenLite seems to have quickly become something of a Flash standard. It's a great library that is well maintained and just works.

PercentMobile – Free Mobile Analytics

April 11th, 2009

My buddy Stan Wiechers just launched a supercool new service that provides Free Mobile Analytics - PercentMobile. Check it out if you want to see how many of your users are viewing your site on a mobile device and what kind of device they are using. To sign up you can use the invite code "airtight" (good for 100 invites).

SWFAddress Gotcha: Navigating Directly to a Deep Link Breaks Preloader

April 1st, 2009

There is a known issue with SWFAddress 2.2: When navigating directly to a deep link, the preloader does not display or jumps straight to 100%. When using the '#' symbol in the URL, the browser loads the main SWF twice which cause the preloader to break.

The fix is to use a mini pre-preloader as supplied in the SWFAddress samples ('samples/cs3/c.fla'). The mini-loader is loaded twice but since it's so small it doesn't matter. I'm adding this information here since the issue is pretty buried in the SWFAddress forum.

[UPDATE] OK, another SWFAddress gotcha by virtue of obscurity: If your back button is not working, check you have specified the 'id' attribute in the swfobject.embedSWF() call. The 'id' attribute can be any string.

swfobject.embedSWF('c.swf?path=main.swf', 'flashContent', '100%', '100%', '9.0.45', null, {}, {}, {id: 'myId'});

A New ‘Battle of the Planets’ Movie !?!

March 28th, 2009

gatchaman

I just found out that there is a new 'Battle of the Planets'/G-Force/Gatchaman movie coming out!

I used to love BOTP as a kid in the 80s. The weirdness and the beautiful animation really made it stand out from the typical U.S. cartoon dross. It was only later that I found out the original Japanese version (Gatchaman) was a lot stranger and more violent.

It’s interesting that even though the show was butchered for the western market, the original spirit shone through. I wonder if as western kids we would have been able to handle the original version, or if we needed the sugar coating of more linear plot-lines, Casey Kasem and 7-Zark-7.

Thru-You

March 4th, 2009

thruyou
Genius.

Ffffound Alternatives

February 10th, 2009

ffffound

There is so much great stuff on Ffffound that you can easily spend all day there browsing images. Ffffound is a fantastically well designed image bookmarking site by tha ltd, the brain child of famed Japanese Flash master Yugop. Ffffound has wisely chosen to keep membership by invite only in order to keep up the quality of the submissions. Which is great unless you don't have an invite.

Vi.sualize.us is a good alternative for the rest of us, despite have one of the worst URLs ever (try remembering it). It's a nice and responsive web app that makes image bookmarking a one-click operation (especially via their Firefox plug-in). Until now I've bookmarked web images by dragging them to my desktop, but that's so 2004. In my quest to push all my personal data into the cloud, I'm now uploading all my image bookmarks.

Another source of cool images is the new tumblr image blogs that are popping up recently such as this isn't happiness and arts and crafts. These image blogs mainly showcase found web imagery of the cool and/or retro variety. Subscribing to the feeds ensures great quality images interspersed among your daily news stories.

Best Flash Upgrade Prompt Ever?

January 18th, 2009

upgrade!

Noticed this upgrade prompt when viewing the TODAY, CREATE. blog through Google Reader. I don't think it could be any more to-the-point ;)

Server Migration Woes

January 8th, 2009

server fail

My apologies for the site downtime over the last few days. It's been a very frustrating experience.

The trouble began when I decided to move this site from its current host (web.com) to a MediaTemple (dv) account I use to host some of my other sites. The idea was to improve site performance. Once the static files, blog and forum were copied over and the DNS was flipped, the MT server crashed. The server continued to crash over the next few days.

Despite repeated tech support calls, no one has been able to tell me why the server is crashing or how I can fix it, so I've been forced to revert back to my original host for the time being. Unfortunately some forum posts have been lost in the database shuffle. If your post has disappeared, please re-post it. Again I apologize for the inconvenience.


Bad Behavior has blocked 2001 access attempts in the last 7 days.