/**
* 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.
코멘트
2의 “URLNavigator class.”에 대한 답변
와~ 좋은데요?
Shift키이면 새 창, Ctrl키이면 새 탭으로 열리는 것까지 구현이 가능하면 좋겠는데…
그렇게 까지 설정이 되지는 않는듯 하네요.