ActionScript 3.0 doesn't manage all developers needs, so often they have to use other languages, as JavaScript, to accomplish some operations like open an HTML popup or get the userAgent property, useful to know the user Browser.
The AS3 ExternalInterface class allow to invoke Javascript functions directly from Flash.
Usually these functions are defined inside the HTML page but in this sample we'll see how to implement them inside an ActionScript class, avoiding to edit HTML code.
USAGE:
import com.fabiobiondi.utils.URLUtil;
1) URLUtil.checkBrowser()
2) URLUtil.openWindow( 'http://www.google.com', '_blank', 'width=400,height=200,scrollbars=yes')
The AS3 ExternalInterface class allow to invoke Javascript functions directly from Flash.
Usually these functions are defined inside the HTML page but in this sample we'll see how to implement them inside an ActionScript class, avoiding to edit HTML code.
USAGE:
import com.fabiobiondi.utils.URLUtil;
1) URLUtil.checkBrowser()
2) URLUtil.openWindow( 'http://www.google.com', '_blank', 'width=400,height=200,scrollbars=yes')
package com.fabiobiondi.utils {
import flash.external.ExternalInterface;
public class URLUtil {
/**
* Open a popup window
* @param url link to open
* @param target window target
* @param options popup options
*
*/
public static function openWindow( url : String,
target : String = "_blank",
options : String = "") : void {
ExternalInterface.call("window.open", url, target, options);
}
/**
* Get the Browser Type
* @Return the userAgent property
*
*/
public static function checkBrowser():String {
var userAgent:String =
String(ExternalInterface.call("function() {return navigator.userAgent;}"));
return userAgent;
}
}
}

