URLNavigator class.
Friday, April 4th, 20081 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | /** * URLNavigator * * The URLNavigator class extends the Flash built-in method, navigateToURL. * This class copies the Firefox browser's link-click action. * If you click on a link with the "Ctrl" key held down, the link will be opened in a new window or a new tab, depend on the browser's settings. * Or Flash Player tries to download the url, if the "Alt" key is held down. * * @author: Han Sanghun (http://hangunsworld.com, hanguns@gmail.com) * @created: 2008 04 04 * @last modified: 2008 04 04 * * Modify Histories */ package com.hangunsworld.net{ import flash.net.navigateToURL; import flash.net.URLRequest; import com.hangunsworld.net.Downloader; public class URLNavigator{ // Downloader object. var dloader:Downloader; /** * Constructor function. */ public function URLNavigator(){ dloader = new Downloader(); }// end constructor /** * Handles the URL depending on the properties provided. * * @param ur An URLRequest object. * @param target A String value specifies the target window. [OPTIONAL] * @param ctrlkey A Boolean value indicates whether the "Ctrl" key is held down. [OPTIONAL] * @param altkey A Boolean value indicates where the "Alt" key is held down. [OPTIONAL] */ public function navigateToURL(ur:URLRequest, target:String="_self", ctrlkey:Boolean=false, altkey:Boolean=false):void{ if(ctrlkey){ // If "Ctrl" key is held down, // opens the URL in a new window or a new tab, depend on the browser's settings. flash.net.navigateToURL(ur, "_blank"); }else if(altkey){ // If "Alt" key is held down, // downlaods the URL via a Downloader object. dloader.downloadURL(ur); }else{ // Otherwise, opens the URL in the window specified by the "target" parameter. flash.net.navigateToURL(ur, target); } }// end navigateToURL }// end class }// end package |
Usage sample code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import com.hangunsworld.net.URLNavigator; stage.addEventListener(MouseEvent.CLICK, clickListener); var un:URLNavigator = new URLNavigator(); function clickListener(e:MouseEvent):void{ var url:String = "http://hangunsworld.com/blog"; var ur:URLRequest = new URLRequest(url); un.navigateToURL(ur, "_self", e.ctrlKey, e.altKey); } |
You can download the class file here.


