External Interface

ExternalInterfaceBuffer source code by Scott Morgan

package com.yahoo.webapis.maps.utils {

public class ExternalInterfaceBuffer {

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

private static var instance:ExternalInterfaceBuffer = new ExternalInterfaceBuffer();
private var methodQueue:Array = new Array();
private var methodCallInterval:Number;

public function ExternalInterfaceBuffer() {
if( instance ) throw new Error( “Singleton and can only be accessed through Singleton.getInstance()” );
}

public static function getInstance():ExternalInterfaceBuffer {
return instance;
}

public function addCall(obj:Object):void {
methodQueue.push(obj);
if (isNaN(methodCallInterval) || methodCallInterval == 0) {
methodCallInterval = setInterval(methodChurn, 50);
}
}

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;
}
}


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: