From 4d6166dc125dc43bd80f6c93fdfb5e5e6e5761fb Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Tue, 25 Jul 2006 02:10:20 +0000 Subject: [PATCH] Added a safe navigateToURL method for sending the browser to some page. If the user embeds the flash client on their own page, if someone then clicks something to visit a msoy page, we will be unable to load that page in that same tab/window. Instead, we'll be forced by flash security restrictions to open in a blank window. Allow for either method, falling back to a blank window if the other method fails. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4289 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/NetUtil.as | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/as/com/threerings/util/NetUtil.as diff --git a/src/as/com/threerings/util/NetUtil.as b/src/as/com/threerings/util/NetUtil.as new file mode 100644 index 000000000..1b47fed06 --- /dev/null +++ b/src/as/com/threerings/util/NetUtil.as @@ -0,0 +1,36 @@ +package com.threerings.util { + +import flash.net.URLRequest; +//import flash.net.navigateToURL; // function import + +public class NetUtil +{ + /** + * Convenience method to load a web page in the browser window without + * having to worry about SecurityErrors in various conditions. + */ + public static function navigateToURL ( + url :String, newWindow :Boolean = false) :void + { + var ureq :URLRequest = new URLRequest(url); + if (!newWindow) { + try { + flash.net.navigateToURL(ureq, "_self"); + return; + } catch (err :SecurityError) { + // ignore; fall back to using a blank window, below... + } + } + + // open in a blank window + try { + flash.net.navigateToURL(ureq); + } catch (err :SecurityError) { + Log.getLog(NetUtil).warning( + "Unable to navigate to URL [e=" + err + "]."); + } + } + + +} +}