[태그:] navigateToURL

  • URLNavigator class.

    /**
     * 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.

    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.