Jumping off of Joey's post about anonymous functions from externalinterface, here's a quick and perhaps obvious method of dynamically getting JavaScript properties:
package examples {
import flash.external.ExternalInterface;
public class JavaScript {
public static function getProperty(name:String):Object {
var property:Object;
if (ExternalInterface.available) {
property = ExternalInterface.call("function() { return " + name +"; }");
} else {
property = new Object()
}
return property;
}
public function JavaScript() {}
}
}
The getProperty() method creates a dynamic anonymous function that simply returns a value.
With such a utility, you can easily access JavaScript properties like so:
trace(JavaScript.getProperty("window.location.href"));
Who needs the FABridge? Just kidding...
Probably less obvious, but you can make use of the toString method of any in-page property.
This works directly from flash without the need to setup any JS methods in the page beforehand.
ExternalInterface.call( “window.location.href.toString” );