REQUEST_URI in Flex
Mar. 7, 2007 9 Comments Posted under: ActionScript, Flex
I recently found it very hard to discover the current URL in the browser from within my Flex aplication. I needed it so I knew which SOAP server to connect to depending on if the instance of the application was on dev, staging or live.
So in order to get the current URI I used this:
import flash.external.*; // Put this in the package
var currentUri:String = ExternalInterface.call("window.location.href.toString");
Then you can go about hacking it with string functions or regexp as you wish!
This entry was posted on Wednesday, March 7th, 2007 at 7:10 pm and is filed under ActionScript, Flex. You can leave a comment and follow any responses to this entry through the RSS 2.0 feed.
would this work in flash? , when i try in flash8 AS2 i cant import the package without errors
but:
gives me an error
if i change it to
:/
damn, i meant:
when i try in flash8 AS2 i _CAN_ import the package without errors
and i also meant to write
“if i change it to var currentUri:Object”
this is going well =/ sorry for meesing up.
Try tracing:
document.location.href
and see what it returns. You shouldn’t be getting that error as you are saying .toString()
I have never developed in flash though so can’t really help. Sorry
Of course, this only works if “allowScriptAccess” is not set to “never”. Which is where I find myself… :(
Where would it be set to never?
I happen to be addressing this same problem. I forget where I saw this trick, but this works for me (adapted for your variable names)
var currentUri:String = String( ExternalInterface.call(” function(){ return document.location.href.toString();}”));
So, the idea is that your call statement calls a function defined on the fly and returns the value you are interested in.
Flash ä¸å?µæ¸¬åµŒå…¥é ?é?¢ç¶²å?€…
Flash在內建æ??供的執行期間環境變數ä¸ï¼Œæ²’有直æ??供嵌入é ?é?¢ä¾†æº?ç¶²å?€è³‡è¨Šï¼Œ\r\n但還是å?¯ä»¥ç”¨ExternalInterface利用javascriptå?–å¾—é ?é?¢ç¶²å?€ã€‚\r\n如æ¤ä¾¿å?¯ä»¥å?šåˆ°åˆ¤æ–·é ?é?¢åµŒå…¥ä¾†æº?來決定是å?¦åŸ·è¡ŒF…
I have been on this referer issue for ages!!
the :
var url:String = String( ExternalInterface.call(” function(){ return document.location.href.toString();}”));
worked a charm!! Im using as2 and flash 8..
as3 is almost the same which is why it was killing me.