Archive

You are currently browsing the archives for the Actionscript category.

Dec

16

Critical Mass releases Google Maps Flash API

By scott

My previous team of Flash Developers at Critical Mass have recently released the start of a Flash API for the popular Google Maps API. You can read more about it here.

Currently AS2 is only supported, they mention an AS3 version will be available sometime in 2008, hopefully early 2008. I have heard from a few people that Google is about to release their own Flash API but until then we have Scott Ingalls and the entire Flash team at Critical Mass to thank.

Nov

18

AS3 Garbage Collection, the reason your tweens are ending early.

By scott

Josh Tynjala and I were speaking today, well actually typing over IM. We were discussing a problem we both ran into recently, the fl.transitions.Tween class was not dispatching events consistently. Sometimes the TweenEvent.MOTION_FINISH event would be broadcasted, other times it would not. Sometimes our programmatic tweens were visually completing, other times they would not, in a few cases they wouldn’t even start. After a little debugging we realized that the AS3 Garbage Collection was killing the tweens. You may be asking why would the garbage collection be doing this? Let’s start out by looking at some example code.

var len:int = _model.getNumberOfItems();
for (var i:int = 0;i<len;i++)>
     var clip:MovieClip = _scope.getChildByName('button'+i);
     var myTween:Tween = new Tween(clip, 'alpha', Regular.easeOut, 0, 1, 0.5, true);
     myTween.addEventListener(TweenEvent.MOTION_FINISH, buttonAnimationComplete);
}

Pretty simple code, in my AS2 days I used code similar to this a million times and never had a problem. All I am doing is looping through a set number of MovieClips and fading them up from 0 to 100%. Most times this worked fine, but a few times the tweens never completed and buttonAnimationComplete was not called. This is because the AS3 Garbage Collection was deleting the Tweens just like it should be. What? The tweens should be deleted? Yes.

Notice that I am storing the reference to my tween in a local variable that gets overridden in every iteration of the loop. This means there is no real reference to the object and when there is no reference to an object it is flagged for removal by the garbage collector. Since there is no real way to know when the garbage collection cycle is going to run the tweens were completing some of the time and other times were being thrown into the back of the big garbage truck that slowly creeps around your code.

The best way to ensure that this doesn’t happen is to store your reference in a class level member. I ended up storing all of my tween references in a class level array. Once all of the tweens were complete I cleared the array. Here is the updated code that I used, the entire class is not shown here, trust me your scroller will thank me.

private var _buttonTweens:Array = new Array();
private var _buttonTweenCompleteCount:int;

private function animateButtons():void {
     var len:int = _model.getNumberOfItems();
     for (var i:int = 0;i<len;i++)>
          _buttonTweens.push(new Tween(clip, 'alpha', Regular.easeOut, 0, 1, 0.5, true));
          _buttonTweens[_buttonTweens.length - 1].addEventListener(TweenEvent.MOTION_FINISH, buttonAnimationComplete);
     }
}

private function buttonAnimationComplete(e:TweenEvent):void {
     buttonTweenCompleteCount++
     if (buttonTweenCompleteCount == _model.getNumberOfItems()) {
          _buttonTweens = [];
          dispatchEvent(new Event('buttonsReady'));
     }
}

I am just using Tweens as an example, but you can run into this same issue with any object that has local references that are overridden. For example, I had a Timer event set to iterate every 100 milliseconds and it called loadAsset(), a method that did just what it says, it loaded an asset.

private function loadAsset():void {
     _currentItemToLoad++;
     var myLoader:Loader = new Loader();
     myLoader.addEventListener(Event.COMPLETE, assetLoaded);
     myLoader.load(new URLRequest('images/galleryImage' + currentItemToLoad + '.jpg'));
}
private function assetLoaded(e:Event):void {
     var holder:Sprite = new Sprite();
     holder.visible = false;
     holder.addChild(e.target.content);
     _scope.addChild(holder);

     e.target.removeEventListener(Event.COMPLETE, assetLoaded);
}

Just like the Tween example above my Event.COMPLETE event was not firing all the time. This is because I was storing the reference to the Loader in a local variable that was overridden each time the loadAsset method was called. To get around this I stored all my references in a class level member (an object or an array work nicely).

Hopefully this helps you figure out why you are not seeing certain events in your code, it had me stumped for a bit. Now you know, and as G.I. Joe said “knowing is half the battle”.

Nov

15

Grant Skinner’s OSX Squeeze Effect in AS3

By scott

First off, thank you Grant for releasing the source for your squeeze effect. Dirty code is better than no code. After looking at the source code I began to wonder how much better it would run in AS3 so I converted it. I didn’t clean up any of the code, just a straight conversion. It seems to run a little smoother. Next I am going to make it dynamic allowing you to load in an image passed in through flashVars. Maybe if I’m really bored I will set it up so you can load in multiple images from an xml file and build a gallery type app using this effect. Again, thanks Grant, as always, very cool work!


 
Download the rough AS3 source here.
 

Nov

11

Accessing document class of an externally loaded swf with AS3

By scott

I have seen a lot of posts lately with people asking how they can access variables and methods in an external swf that is loaded at runtime using AS3. This isn’t a difficult task, but it is much different than AS2/AS1 where you could just call directly into the loaded swf using the instance chain if you were in the same security sandbox.

First off, lets create our swf that wil be loaded in at runtime. Open up your favourite actionscript editor and create a new class with the following code.

package com.scottgmorgan {
     import flash.external.ExternalInterface;
     import flash.display.Sprite;
     public class ExternalMovie extends Sprite {
          public function ExternalMovie():void {
               //nothing in our constructor right now.
          }
          public function alert(msg:String):void {
               trace(msg);
               ExternalInterface.call('alert', msg);
          }
     }
}

Now create a new FLA and set the above class as the document class. If you are not sure how to do this simply enter the class path (com.scottgmorgan.ExternalMovie) into the document class textfield found in the property panel. Lather, rinse, repeat, compile.

Next we will create the swf that will load our ExternalMovie swf we just created. Let’s jump back to our favourite actionscript editor and create a new class with the following code.

package com.scottgmorgan {
     import flash.display.Loader;
     import flash.net.URLRequest;
     import flash.events.Event;
     import flash.display.LoaderInfo;
     import flash.display.Sprite;
     public class SourceMovie extends Sprite {
          public function SourceMovie():void {
               var loader:Loader = new Loader();
               loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
               loader.load(new URLRequest('ExternalMovie.swf'));
          }
          private function onLoadComplete(e:Event):void {
               var loaderInfo:LoaderInfo = e.target as LoaderInfo;
               addChild(e.target.content);
               var swf:Object = loaderInfo.content;
               swf.alert('Hello World');
          }
     }
}

That’s it, LoaderInfo saves the day. LoaderInfo.content connects you with the document class of the externally loaded swf. Lets create a new FLA, assign the SourceMovie class as the document class and compile. Make sure the SourceMovie.swf and ExternalMovie.swf are in the same directory. The as files should be in /com/scottgmorgan/. Let’s compile the SourceMovie and you should see “Hello World” in the output window if you run the swf inside the IDE, if you run it from a browser you should see an alert dialog with “Hello World”.

Another option you have is to use the ApplicationDomain class. Using the ApplicationDomain class you can add the classes from the ExternalMovie to the SourceMovie’s ApplicationDomain. This is a great way to load in code libraries at runtime.

Lets pretend we have a large application with multiple levels of security, maybe we are creating a content management system and we need multiple permission levels. User A can only update content, User B can update content and update the site map, User C is an administrator and can do everything User A and B can do but can also access tracking information, edit user profiles, update permissions, etc. When User B logs in the application loads the site map code library (sitemapadmin.swf) and adds its classes to the main ApplicationDomain. When User C logs in the sitemapadmin.swf classes would be added to the main ApplicationDomain, for this user the application would also load the trackingadmin.swf, and useradmin.swf code libraries and add all the included classes to the main ApplicationDomain.

Let’s update our SourceMovie.as file and add the ExternalMovie class to SourceMovie’s ApplicationDomain.

package com.scottgmorgan {
     import flash.display.Loader;
     import flash.net.URLRequest;
     import flash.events.Event;
     import flash.display.LoaderInfo;
     import flash.display.Sprite;
     import flash.system.ApplicationDomain;
     public class SourceMovie extends Sprite {
          public function SourceMovie():void {
               var loader:Loader = new Loader();
               loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
               loader.load(new URLRequest('ExternalMovie.swf'));
          }
          private function onLoadComplete(e:Event):void {
               ApplicationDomain.currentDomain.getDefinition("com.scottgmorgan.ExternalMovie");
               var myExternalMovie:ExternalMovie = ExternalMovie(e.target.content);
               myExternalMovie.alert('Hello World');
          }
     }
}

There you have it. One thing you will notice is you don’t have to add the loaded swf to the display list to access its classes. Hopefully you will be able to use these techniques in future projects.

Oct

22

Say hello to my little friend – describeType()

By scott

It amazes me that people don’t know about describeType(). If you’re lazy, or as some developers call it, efficient, you always don’t have time, or really don’t feel like digging through half assed completed documentation to see what parameters a classes constructor accepts. Sounds like the perfect time to combine forces, trace() meet flash.utils.describeType(). The describeType() method returns an xml dump that contains all the details you’d ever need to know about any object that is passed in as a parameter.For example, let’s pretend this is our first time working with Flash (of course you could be working in Flex too), lucky us, we never had to use AS2 or AS1, we only heard our cubicle neighbors groaning about spaghetti code, and hidden code attached to buttons. Since this is our first time using Flash we don’t even know what a MovieClip is or what methods are available to us. One simple line of code will solve our ignorance.

trace(flash.utils.describeType(flash.display.MovieClip));

This one little line of code returns this to us in our output window (shortened for your scroll wheels sake):

<type name="flash.display::MovieClip" base="Class" isDynamic="true" isFinal="true" isStatic="true">  <extendsClass type="Class"/>  <extendsClass type="Object"/>  <accessor name="prototype" access="readonly" type="*" declaredBy="Class"/>  <factory type="flash.display::MovieClip">    <extendsClass type="flash.display::Sprite"/>    <extendsClass type="flash.display<::DisplayObjectContainer"/>    <extendsClass type="flash.display::InteractiveObject"/>    <extendsClass type="flash.display::DisplayObject"/>    <extendsClass type="flash.events::EventDispatcher"/>    <extendsClass type="Object"/>    <implementsInterface type="flash.display::IBitmapDrawable"/>    <implementsInterface type="flash.events::IEventDispatcher"/>    <accessor name="scenes" access="readonly" type="Array" declaredBy="flash.display::MovieClip"/>    <method name="stop" declaredBy="flash.display::MovieClip" returnType="void"/>    <method name="nextScene" declaredBy="flash.display::MovieClip" returnType="void"/>    <method name="play" declaredBy="flash.display::MovieClip" returnType="void"/>    <accessor name="currentScene" access="readonly" type="flash.display::Scene" declaredBy="flash.display::MovieClip"/>    <accessor name="currentFrame" access="readonly" type="int" declaredBy="flash.display::MovieClip"/>    <accessor name="trackAsMenu" access="readwrite" type="Boolean" declaredBy="flash.display::MovieClip"/>    <method name="gotoAndStop" declaredBy="flash.display::MovieClip" returnType="void">      <parameter index="1" type="Object" optional="false"/>      <parameter index="2" type="String" optional="true"/>    </method>    <accessor name="currentLabels" access="readonly" type="Array" declaredBy="flash.display::MovieClip"/>    <method name="willTrigger" declaredBy="flash.events::EventDispatcher" returnType="Boolean">      <parameter index="1" type="String" optional="false"/>    </method>  </factory></type>

The output window never looked so good. Methods, paramaters, superclasses, accessors, the amount of information that is returned is beautiful. I don’t know how many for in loops I wrote in AS2 just to try and figure out what methods were available in a custom class.One thing to note is that describeType() only shows public properties and methods, and will not show properties and methods that are private, package internal or in custom namespaces.If you have never looked at the flash.utils.* package, I suggest you do, there are some handy little utilities in there.

Oct

5

Thermo == speechless! However, I do have questions?

By scott

Google defines Thermo as “Two bars or wires of dissimilar metals joined at one extremity which Couple develop a current (thermoelectric current) when heated.” I define it as a major accomplishment for Adobe that is reinventing the term “Deseloper“. Aral Balkan has posted videos from the sneak peak at Max, too cool.

This is a very early sneak peak, possibly even some smoke and mirrors, but still, Adobe has hit the nail on the head and may have finally beat the Flex Project workflow issues. Watching these videos do bring up a few questions.

Are Thermo projects bound to the original assets? If the developer are working on a project together and the designer changes something in the design will Thermo automatically update the MXML. Obviously within reason, but say the designer moved the Favorites album list above the top list. Whould Thermo recognize this and make the change without the developer intervention?

All of the styles appear to be inline in the demo, can they be extracted into CSS for runtime styling? For larger applications this is mandatory for projects that are multilingual or are available under multiple brands.

What about working the other way? Open MXML in Photoshop? I don’t know how many times I have had designers take a screengrab of something I am working on, hack it apart in Photoshop just to show me what they want. Obviously they could do some of this in Thermo but I doubt Thermo will have every tool that is available in Photoshop and if it is a quick change a designer doesn’t need to learn Thermo, they can make the change, hit Save and the workflow isn’t interupted. This would also allow designers to skin existing components or even a prototype that a developer whipped together to show a concept.

With other WYSIWYG development tools the code output is usually something I wouldn’t want to hang on my fridge. MXML is pretty clean but there are optimizations that can be applied to ensure quicker compilation and easier access via Actionscript. I hope this will be considered. In the end it is all compiled so the output is usually not an issue but as a developer I have opened many files a designer has created with a WYSIWYG applications and have almost fallen out of my chair.

I am sure I will have more questions as I let this sink in. Coming from a design/creative background developer/designer workflows are something I have worked on at most companies I have worked at. I think this is a huge step in the right direction. As long as Adobe doesn’t create a visual tool for creating business logic my job will be secure when Thermo hits the market :)

Aug

20

Yahoo launches new Flash Blog and new Flash and Flex Libraries

By scott

Well this will probably be my last posting that announces something my team (Yahoo! Flash Platform) at Yahoo has launched. From now on it will be my former team as I am leaving to work for Disney on Friday. This week we launched three very exciting things. The new Yahoo! Flash Platform blog (http://www.yswfblog.com), the new and improved Yahoo! Flash Development Center (http://developer.yahoo.com/flash) and our new Astra Flash Components. The Astra Library is our collection of Flash and Flex components, libraries and toolkits. In this inaugural release, ASTRA contains five UI components that complement the existing set provided with Flash CS3. The new UI components are: Tree, Menu, TabBar, AutoComplete, and Charts. ASTRA is open-source under the BSD license, and follows an approach similar to the very popular YUI Library. Keep an eye on the ASTRA library, I know first hand that there are some very cool things to come.

Jun

18

Runtime Font Embedding in AS3. There is no need to embed the entire fontset anymore.

By scott

Well, pulled a few more hairs out today. Hard to believe I have any left. I am working on a multi-lingual application that needs embeded fonts. As most of you know, loading every character in a given fontset equates to one big ass swf. For example, if you want to embed a regular and bold Japanese font you’re looking at approx. 13 megs, and depending on the quality of the font you could be close to 20 megs. That’s a lot of font. In an ideal world the Flash Player would allow for dynamic runtime shared font libraries that allow for only a subset of characters to be embeded.

In AS2 there were a few ways (hacks) to load font libraries at runtime. Unfortunately none of the AS2 hacks work in Flash CS3 using AS3. However, there is an answer. In Flex you can embed fonts at compile time using the [Embed] metadata tag in your Actionscript. And the best part is you can use the unicodeRange attribute to define a subset of characters you want to embed. Below is a class I created that compiles a swf that contains all Latin I characters in the Arial font.

package {
     import flash.display.Sprite;
     public class _Arial extends Sprite {

          [Embed(source='C:/WINDOWS/Fonts/ARIAL.TTF', fontName='_Arial', unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E')]

          public static var _Arial:Class;

     }
}

A couple things to point out here. The fontName attribute value can not be the same name as a device font. If I were to change my code to use fontName=’Arial’ the compiler throws the following warning “the embedded font ‘Arial’ may shadow a device font of the same name. Use fontName to alias the font to a different name”. To get around this I simply added an underscore before the name. From this point on you must reference the _Arial in your TextFormats or CSS. Now if you compile that it will create a swf named _Arial.swf.

Ok, great, now what? Well, now you have to load the font into the application. Here is a sample class that loads in the font and displays some rotated text just to prove that it is embeded.

package {
     import flash.display.Loader;
     import flash.display.Sprite;
     import flash.events.Event;
     import flash.net.URLRequest;
     import flash.text.*;

     public class FontLoader extends Sprite {

          public function FontLoader() {
               loadFont("_Arial.swf");
          }

          private function loadFont(url:String):void {
               var loader:Loader = new Loader();
               loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fontLoaded);
               loader.load(new URLRequest(url));
          }

          private function fontLoaded(event:Event):void {
               var FontLibrary:Class = event.target.applicationDomain.getDefinition("_Arial") as Class;
               Font.registerFont(FontLibrary._Arial);
               drawText();
          }

          public function drawText():void {
               var tf:TextField = new TextField();
               tf.defaultTextFormat = new TextFormat("_Arial", 16, 0);
               tf.embedFonts = true;
               tf.antiAliasType = AntiAliasType.ADVANCED;
               tf.autoSize = TextFieldAutoSize.LEFT;
               tf.border = true;
               tf.text = "Scott was here\nScott was here too\nblah scott...:;*&^% ";
               tf.rotation = 15;

               addChild(tf);
          }
     }
}

And there you have it. Run time embeded fonts. The key lines to look at here are

var FontLibrary:Class = event.target.applicationDomain.getDefinition("_Arial") as Class;

The getDefinition method returns a reference to the _Arial class loaded in through the swf (event.target). The next line:

Font.registerFont(FontLibrary._Arial);

registers the loaded in _Arial font in the global font list. If you were to trace out the results of Font.enumerateFonts() you will now see _Arial at the top of the list.

Now lets say your site was in a few different languages you may add the following line to the FontLoader constructor to load language specific fonts at runtime.

public function FontLoader() {
     var langManager:LanguageManager = LanguageManager.getInstance();
     var langID:String = langManager.getLanguageCode(); //returns jp
     loadFont(langID + "_Arial.swf");
}

Instead of loading in _Arial.swf the application will load in jp_Arial.swf. jp_Arial.swf would be another generated font swf like the _Arial example above but this time the unicodeRange would only include the Japanese fonts you need. All you have to do now is create a CSS file and fonts for each language, store the proper language code somewhere within the application and use that language code when loading your CSS files and fonts.

You may not know this but Adobe has supplied us with sample unicodeRanges in the following file “\Applications\Adobe\Flex Builder 2\Flex SDK 2\frameworks\flash-unicode-table.xml”. You can either use one of the supplied ranges or create your own. You may only need to embed a few characters, if so just list the unicode values of the characters you want each seperated by a comma.

Sounds pretty straight forward eh? Or is it????

In doing this I ran into a huge bug using Flex Builder to generate the font swfs. When I was experimenting with the unicodeRanges my compiled versions did not contain the proper character ranges that I specified. For example I would define a range that only contained Uppercase characters. In my test font loading app I would only see numbers. Only if I removed the unicodeRange attribute would I see all my characters. This led me to believe that Adobe had documented something that really wasn’t part of the compiler. I tried deleting files, I was checking timestamps, nothing. Then I tried to clean my project before compiling (In FlexBuilder select Project > Clean). It worked! The subset of characters I defined in my unicodeRange only loaded into my test app. YAY! Then I tried switching the unicodeRange again. DOH! nothing. Cleaned project again and BINGO!

Lesson learned: Whenever you change your unicodeRange clean your project before you compile or else your change may not be compiled properly.

I haven’t tried this in Flex 3 yet to see if the bug has been addressed. I did look at the Flex 3 bug system and didn’t see it listed. Either it has been fixed or no one has run into this issue yet. It is pretty obscure I guess.

May

18

Featureblend.com just released new Javascript Flash utilities.

By scott

A friend and colleague of mine Carl Yestrau just released a few Javascript Flash utilities. Check them out and let him know what you think. “I am happy to share with the Flash community a series of JavaScript Flash utilities. All are freely available under the BSD license. A detailed set of supporting documentation is available online.

JavaScript Flash Detection Library (Flash Detect)
A JavaScript library designed to simplify the process of detecting if the Flash Player is installed in a Web Browser. Major, minor and revision version information is made available in the API.

JavaScript Flash HTML Generator Library (Flash TML)
A JavaScript library designed to simplify the process of generating the required HTML for adding a Flash movie to a web document. Follows a standards compliant approach to markup generation using the object element.

I hope these libraries serve you well!”

Apr

1

My ExternalInterfaceBuffer source code

By scott

I have had many people request that I post the code to my ExternalInterfaceBuffer class that I made reference to in my ExternalInterface…HELP posting. This code is part of the Yahoo Maps AS3 Communication Kit that I wrote and can be downloaded from the Yahoo! Flash Developer Network. As a bonus you will also get some other very cool Yahoo! AS3 API wrappers, Search, Answers, Weather, and Upcoming.org. To make a long story short, the issue I noticed was some of my ExternalInterface calls were getting dropped. I did a boat load of debugging, and discovered it was actually the browser script engines overloading and dropping the calls. So I wrote a singleton class that queues up all the ExternalInterface calls and sends them one at a time in 50 second intervals. One thing I noticed, 50 second intervals works fine with Actionscript 3, Actionscript 2 is a lot slower so I had to slow it down to 100 miliseconds or else I was running into the same issues, just not as often.

/*
Copyright (c) 2007, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:

http://developer.yahoo.net/yui/license.txt

version: 2.2.0
*/
package com.yahoo.webapis.maps.utils {

     import flash.external.ExternalInterface;
     import flash.utils.setInterval;
     import flash.utils.clearInterval;

     /**
      * Utility to buffer outgoing ExternalInterface calls. Simoltaneous
      * calls get dropped if they aren't buffered. It seems both Firefox and
      * IE's script engine gets overloaded and either drops calls or
      * throws a javascript error. This buffer ensures the script engines
      * only get one call at a time.
      *
      * @langversion ActionScript 3.0
      * @playerversion Flash 9
      * @author Scott Morgan 02/25/2007
      *
      * @see flash.external.ExternalInterface
     */
     public class ExternalInterfaceBuffer {

          /**
           * @private
           * A singleton class that is accessed by almost all classes in this
           * communication kit. This static variable gives access to this class
           * ensuring there is only ever one instance of it.
           *
           */
          private static var instance:ExternalInterfaceBuffer = new ExternalInterfaceBuffer();

          /**
           * @private
           * An array of methods waiting in the queue to be called. Once they
           * are called they are removed from the array.
           *
           */
          private var methodQueue:Array = new Array();

          /**
           * @private
           * Access to the interval that runs while the methods are being called.
           * When all methods in the queue are called this variable is used to
           * clear the interval.
           *
           */
          private var methodCallInterval:Number;

          /**
           * Constructor
           * If an instance of this class already exists an error message is thrown
           * informing that this class should only be accessed through the getInstance()
           * method.
           *
           * @see com.yahoo.webapis.maps.utils.ExternalInterface.getInstance()
           */
          public function ExternalInterfaceBuffer() {
               if( instance ) throw new Error( "Singleton and can only be accessed through Singleton.getInstance()" );
          }

          /**
           * @public
           * This static method is what makes this class a singleton, it ensures that only
           * one instance of this class is instantiated.
           *
           */
          public static function getInstance():ExternalInterfaceBuffer {
               return instance;
          }

          /**
           * @public
           * Method used to add calls to the methodQueue array. If the length of the methodQueue
           * array is greater than 0 the methodChurn interval is kicked off and runs every 50
           * milliseconds until the methodQueue's length is 0 at which point the interval is
           * cleared.
           *
           * @param obj and object containing a method string, and a data
           * object. The method string is the method the ExternalInterface will
           * call and the data object is the object that will be passed to the
           * calling method as an argument.
           */
          public function addCall(obj:Object):void {
            methodQueue.push(obj);
            if (isNaN(methodCallInterval) || methodCallInterval == 0) {
                methodCallInterval = setInterval(methodChurn, 50);
            }
          }

          /**
           * @private
           * This method is called every 50 milliseconds until the methodQueue array is empty.
           * This method sends the first method listed in the methodQueue array to the
           * ExternalInterface.call method.
           *
           * @see flash.external.ExternalInterface.call
           */
          private function methodChurn():void {
            if (methodQueue[0].method != undefined && methodQueue[0].method != null) {
                ExternalInterface.call(methodQueue[0].method, methodQueue[0].data);
            }
            methodQueue.shift();
            if (methodQueue.length == 0) {
                clearInterval(methodCallInterval);
                methodCallInterval = undefined;
            }
          }
     }
}

Pretty straightforward stuff. Ok, that’s great, now how do you use it. Simple, one line of code, well two because you have to instantiate the class.

First you have to remember to import the class

import com.yahoo.webapis.maps.utils.ExternalInterfaceBuffer

Then you have to instantiate, you may choose to write one line of code to instantiate the class and call the addCall method in one line. I was used this class multiple times in the class so I instantiated it once and made reference to it with a variable scoped to the class.

private var EIBuffer:ExternalInterfaceBuffer = ExternalInterfaceBuffer.getInstance();

And lastly, add your call to the queue by calling the public addCall method. This method expects an object containing a String containing the method name and an encapsulated data object that contains the arguments you want to pass along to the method being called via the ExternalInterface.

EIBuffer.addCall({method:"myJavascriptMethod", data:{argA:'blah', argB:'merp', argC:'DOH'}});

That’s it, I know I could of made it a bit more elegant but it does everything I needed at the time. Plus it’s open source, now the world can all join in and make it perfect :)

Enjoy!