JSFL

JSFL No Comments »

Not long after I started at MRM did I discover JSFL.  I am amazed at how long I have gone without this utility.  For the uninitiated (as I so recently was), JSFL is JavaScript for Flash - that is, a breed of 100% genuine JavaScript that runs within the Flash IDE.  You can write scripts ending in the “.jsfl” extension and by putting them in certain folder locations you can access these scripts inside Flash through custom panels or commands in the menu bar.

Instead of manipulating web browser DOMs, JSFL lets you manipulate the content of FLAs - publish settings, timeline instances, IDE tools, frame scripts, the works.  JSFL also comes with some utilities for manipulating the file system - finding, reading, writing, and deleting files and directories.  JSFL is a missing link for automating some key Flash workflows; I am amazed that a tool this robust has been seemingly hidden from me for so long.

Don’t take my word for it, though - go read the docs! (Link to PDF)

Just for the hell of it I wrote a little JSFL editor panel.  It’s a mash-up of AS3, Flex and JSFL that lets you write little persistent JSFL snippets in a side-bar and execute them whenever you want.  Granted, when you edit a JSFL file in the proper Flash IDE, you get access to code completion, syntax highlighting, and so on…  But then you have to tab back and forth between your FLA and your JSFL window!  Who wants to bother with that?

I’ll kick it here once I clean it up some.

MRM Worldwide

Uncategorized No Comments »

Time to dust off this old blog.  I spent almost all of 2009 working at BBDO Detroit, and despite that being an excellent time for my growth as a programmer, I didn’t bother to record one word of it here.  It was an amazing year that taught me a great deal about the multimedia business I so wanted to get into as I left the insurance biz behind.  Unfortunately BBDO Detroit lost its only client - Chrysler - as part of the Fiat takeover.  It closed its doors in January 2010.  I may harken back to those days, but rather than commit to chronicling that time in painstaking detail here, I’ll just try to make a habit of using this blog for my professional life going forward.

On December 14th I began my new job at MRM Worldwide in Birmingham, Michigan.  I’m coming up on the end of my second month there.  My feelings so far are captured well by my new boss.  ”In this business, you’re either in a bureaucracy or in the military.  This place is 100% military: ‘you are on a mission’,” he said over drinks at the bar downtown.  My new boss is a likeable character and very evidently respects the members of our Flash team while holding us accountable for our work.  I think we’ll get along fine.

He’s absolutely right, though - MRM is militant, in the best way that can be said I suppose.  We are in the jungle, caught in a wicked crossfire of situations: pleasing a new, huge client (General Motors), working with hundreds people all brand new to the company (brought on specifically to service said client) with no infrastructure and no institutional knowledge except what the executive transition team tries to pipe straight into our brains.  Right now we are essentially a start-up within MRM Worldwide.

The gig is to take on a 5-year contract with General Motors, developing their digital promotions for most of their brands and divisions.  I’m one of the senior Flash developers in the new outfit, and owing to my habit of biting off more than I can chew, have become a more or less de-facto point person / team lead.  This basically means that I help people who are perfectly capable of managing themselves get the information they need to work, and then sweat the details of the code we inherited after The Code Freeze.

You see, February the 1st marked our takeover of chevrolet.com from the previous site provider, Prodigious World Wide.  This was after a grueling 90+ hour code freeze week.  While the code freeze ended better than I anticipated, it has become clear to me that it was essentially an Anti-Christmas for our Flash team.  The Flash code we received in big bundles can be likened to an assortment of presents, and only when you truly and deeply inspect the code (thereby opening the present) do you fully understand the surprises in store for you.  Some of those presents we have already opened and beheld with terror; for lack of time, the others we have only hefted, shaken, and peeked at under the wrapping paper to assess just what kind of terror we may be in for.  Given all the world and time, of course we would discover everything fully, or perhaps rewrite the site; but remember that this is the military.  You are on a mission, and there’s no time for gift unwrapping.

The true problem has to do with the way the site was created, which if I had to guess reflects the pressures surrounding the site’s continual development more than the quality of the developers who did so.  Mixing my metaphors even more thoroughly, the site, being so large, cannot help but be a layer-cake of technological interdependency produced by (I imagine) seventeen hundred frenzied, deadline-driven bakers with wildly different philosophies working in alternate shifts for the better part of a decade.  You can imagine that the resulting layer cake, beneath the frosting, isn’t pretty - especially when you behold its entire scope at once.

This is completely apart from the fact that our team seems to be producing two dozen banners every time we sit down and inhale.  Suffice to say that we are busy.

Still, it is nothing if not a challenge.  I have already learned a great deal as a programmer and despite the emotional ups and downs the place is growing on me.

Recursive Dimensional Clustering

Uncategorized 1 Comment »

http://lab.polygonal.de/index.php?s=quadtree

Start 2009 With Some Links

ActionScript 3.0, Personal No Comments »

To kick off 2009, I decided to trawl my blogroll for fresh ideas.  I keep telling myself that the blogroll has too many links, but when someone posts a great idea or a new AS3 project, it pays to keep their URL around!  Some interesting clippings:

  • Mouse gesture recognition class for Actionscript 3.  If you’ve used a PDA with a stylus to jot notes down, then you have seen the way a touchscreen translates squiggly lines into recognized characters.  This class by Didier Brun does that in Flash.  I haven’t test-driven it, but Didier’s example code looks super easy to use.  If you ever want to deploy an app on a stylus-friendly platform (like a DS), this would come in handy.
  • Unity3D, a plug-in for web-based 3D games, looks sexy as hell.  Go look at that link right now if the thought of buttery-smooth 3D in the web browser fills you with longing.  You’ll notice that Unity3D is not Flash at all - and Flash will not be able to kick out these kinds of results until Adobe gets serious about hardware acceleration (or acquiring Unity3D, I guess).  Curious about performance, features, programming languages for Unity3D?  Well, let John Grden tell you all about it.  He’s actually used it.
  • Josh Tynjala over at Josh Talks Flash has released an update of his Treemap Flex component.  I always think these sorts of tree visualizers are very slick, so I slipped a copy of the Treemap code repository in my back pocket for later.
  • Loudcrowd rocks!  Yes, I’m going to shamelessly plug a web game.  I like dance music, Flash, 3D, and rhythm games.  Loudcrowd mixes all those in a big fat pot and doles out the soup of goodness that emerges.  You chat and dance with other players and listen to music - even if you aren’t playing the game you can get your favorite genre streamed to the browser tab.  Like many successful games, it’s easy to get sucked in but challenging to master.  Even with the CPU overhead of streaming audio, the keypad controls are surprisingly well-synched to the beat.  Maybe it’s not a surprise, since Loudcrowd is made by Conduit Labs.  These ass-kickers include some of the devs who drained my spare time for almost two years are responsible for Guitar Hero.  Um.

That’s all for now - happy  hacking, and Happy 2009!

Flint Particle System

ActionScript 3.0 No Comments »

Just found this today - it’s a particle engine for AS3.  Check it: http://flintparticles.org/

So many awesome AS3 libraries - I just can’t keep up!

Papervision3D Resources

ActionScript 3.0 No Comments »

I’m just beginning to sink my teeth into Papervision3D and it’s a blast. PV3D is definitely still a programmer’s playground. There are few (read: no) formal resources and most PV3D “apps” that I’ve come across are just one-off demos of a textured model, rotating in space.  It will take a great deal of creative thinking and determination to make a really eye-catching and fun app using PV3D - but hey, don’t you want to be the one to do it??

I’ve been frustrated by a lack of documentation, but there are some great resources if you keep digging:

http://pv3d.org/ : Blog with some great hands-on demos and source files.
http://blog.papervision3d.org/ : The official blog. In some ways it’s a promotion of the PV3D platform itself to non-programmers, but it’s still a good resource. Lots of cool examples and links.
http://www.youtube.com/user/mikenku : Mike Lively’s YouTube channel, where he does some bad-ass stuff with PV3D (and 3D in general) with surprisingly little code.
http://professionalpapervision.wordpress.com/ : Mike Lively’s blog, tied closely to his YouTube channel.

FlashVars in ActionScript 3.0

ActionScript 3.0, Hackisms 1 Comment »

FlashVars Not Working, from the Kirupa Forums

Objective: Pass simple HTML variables into your SWF file at run-time.

Problem: Using the param and embed directives doesn’t work, as in <param name=”FlashVars” value=”x=y&a=b”> and <embed … FlashVars=”x=y&a=b”>.  This is what most sites seem to advise, but it didn’t do the trick for me.

Solution: I bet you’re including the Javascript function AC_FL_RunContent() in the HTML page, right?  Wedge a parameter in the huge list there - anywhere - where the first value is ‘FlashVars’ and the second value is your query string.

The resulting method invocation should look something like this:

AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
'width', '550',
'height', '400',
'src', 'Preloader',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'window',

'FlashVars', 'x=y&a=b',
// ^^^ This is the magic line you want to insert.
//Put it anywhere on the list, it shouldn't matter

'devicefont', 'false',
'id', 'Preloader',
'bgcolor', '#000000',
'name', 'Preloader',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','sameDomain',
'movie', 'Preloader',
'salign', ''
); //end AC code

Dynamic Run-Time Icons in Flex with ButtonBar

ActionScript 3.0, Flex 3.0, Hackisms 3 Comments »

I revisited Ben Stucki’s IconUtility class for loading Button icons at run-time.  It works very well, however you can run into some grief using IconUtility with a ButtonBar.

Objective: Load icons for a Flex ButtonBar at runtime.

Problem: Your icons don’t appear to be loading; or, you encounter a compile-time error about converting a UIComponent to an Object when using IconUtility in an Array dataProvider for ButtonBar; or, you encounter a run-time error that the ButtonBar’s dataProvider must not contain DisplayObjects.

Solution: Use IconUtility in conjunction with the ButtonBar’s childAdd event (which dispatches a ChildExistenceChangedEvent).  You can use the handler I wrote below.

The problem we’re running into here is this: using IconUtility with a straight-up Button is cake, because IconUtility.getClass() associates a reference to the Button with the URL of the image you want to load.  But when creating buttons through a ButtonBar, there’s a subtle difference: your buttons don’t exist yet. They have not been created yet by the ButtonBar, and that means IconUtility.getClass() cannot create references on them.  It can try to create references on the objects in your DataProvider, which describe your soon-to-be Buttons, but this doesn’t work; the DataProvider’s child objects are just input parameters for ButtonBar, not the Buttons themselves.

We get around this by listening for the ButtonBar’s childAdd event, which signifies that a Button has been created and can now be referenced. Below is a simple listener function that does exactly that and implements IconUtility for you.  To use it, add the function as an event listener for any ButtonBar’s childAdd event.

import com.benstucki.utilities.IconUtility;
import mx.controls.Button;
import mx.controls.ButtonBar;
import mx.events.ChildExistenceChangedEvent;

public function childAddedHandler(event:ChildExistenceChangedEvent):void
{
var buttonBar:ButtonBar = event.target as ButtonBar;
var button:Button = event.relatedObject as Button;
var data:Object = buttonBar.dataProvider;
var key:String = "icon";

var iconSource:String = data[buttonBar.getChildIndex(button)][key];
button.setStyle("icon", IconUtility.getClass(button, iconSource));
}

Here’s an example of setting up a DataProvider and a ButtonBar using this function.

<mx:Script><![CDATA[
	//childAddedHandler(event:ChildExistenceChangedEvent):void ...
]]></mx:Script>

<mx:Array id="testData">
	<mx:Object id="button1"
		label="Red Button"
		icon="assets/redIcon.jpg" />
	<mx:Object id="button2"
		label="Green Button"
		icon="assets/greenIcon.jpg" />
	<mx:Object id="button3"
		label="Blue Button"
		icon="assets/blueIcon.jpg" />
</mx:Array>

<mx:ButtonBar id="buttonBar"
	dataProvider="{testData}"
	childAdd="childAddedHandler(event);">
</mx:ButtonBar>

It’s not a perfect fix because the DataProvider must be an Array of Objects (rather than a ViewStack or anything else). It can be rewritten to do that; I welcome you to.
As you can see, the function looks for the icon’s URL in the “icon” property of the DataProvider Object. Really you could keep it in any property of the DataProvider object you wanted. The only thing that matters is that ButtonBar always creates Buttons in exactly the same order as the DataProvider Array’s elements.

Flash Player 10 FileReference Controversy

ActionScript 3.0, Personal No Comments »

As I caught up on my blog reading, I found a post on Senocular’s blog about a potentially troubling feature change in Flash Player 10.  Of many security changes, one revolves around the file upload and download potential of the FileReference class.  I haven’t used the class much, but it is the backbone for batch file upload apps used by Flickr, Wordpress, and others as you can imagine.

What Adobe is calling a “security upgrade” and what some others are calling “a catastrophe” is this: in Flash Player 10, you can only invoke the FileReference.browse() and upload() methods in direct response to a “user interaction.” I take this to mean “a callback from a MouseEvent or KeyboardEvent.”  This implies that you cannot invoke these methods when the user input comes from outside the SWF (such as the form in the HTML the SWF is embedded in).  This communication barrier broke a lot of programs.  Adobe’s response is, essentially, “that’s life; fix your program.”  These WordPress folks don’t consider that an acceptable reply.

Lee Brimelow at The Flash Blog had this to say about the recent changes, and posted again when the controversy did not simply fade away.  He recommends developers use a hack to get around this, like absolutely positioning an invisible Flash button over your old HTML button, such that the Flash button will catch the click and begin the upload activity.  If I were Adobe giving that advice, I’d be embarrassed.

Still, I don’t know what to make of the whole thing.  When it comes to security enhancements, Adobe has a huge ass to cover and they need to cover all of it (how many people have Flash Player installed, again?).  They could lose plenty of good standing with Flash Player users (oh yeah, everybody) if a security loophole to upload your entire hard drive were exploited.  But by making security more aggressive, they break some existing apps with (apparently) significant developer communities, and tempt them to try out Silverlight or return to Java.  I do love Flash, but certain competitors have caught a whiff of Adobe’s lunch.

Legato: Dependency Injection Framework for Flex

Flex 3.0 No Comments »

Found this framework originally on a Flex.org post:

Problem Summary: Create application component structure with dependency injection pattern (a type of Inversion of Control). Make it as simple as possible without external XML files.

Solution Summary: Legato Injection framework is an implementation of Dependency Injection Container that can be used as Service Locator as well. It also provides metadata-based injection and uses MXML for configuration.

Read more about Dependency Injection at Wikipedia

Check out the Legato project page