태그 보관물: net

URLNavigator has been modified.

URLNavigator 클래스를 수정하여 링크 이동 뿐 아니라, 자바스크립트도 실행이 가능하도록 수정하였습니다.
아래 코드와 같이 URLNavigator.callJS() 메소드를 통해서 자바스크립트 함수를 호출 할 수 있습니다.
I modified the URLNavigator class to add calling JavaScript function feature. You can use URLNavigator.callJS() method to call a JavaScript function like this.
URLNavigatorクラスを改めてJavaScript函数を呼び出すことが出来るようにしました。下のコードのように、URLNavigator.callJS()メソッドを通じてJavaScript函数を実行出来ます。
1
2
3
4
import com.hangunsworld.net.URLNavigator;
var un:URLNavigator = new URLNavigator();
un.callJS("functionName");
un.callJS("functionName", param1, param2, ..., paramN);
또는 다음과 같이 링크와 자바스크립트가 혼재되어 있는 경우, URLNavigator.analyze() 메소드를 사용할 수 있습니다. 이 경우 타겟이 “javascript”로 설정된 경우 자바스크립트 함수를 실행하고, 이 외의 경우에는 지정된 링크로 이동합니다.
If JavaScript calls are mixed with normal links, use URLNavigator.analyze() method. It calls callJS() method, when the target property is set to “javascript”, otherwise, it goes to the sepcified link.
JavaScriptコルと一般リンクが混じっている場合、URLNavigator.analyze()メソッドを使えます。Targetプロパーティが “javascript”に設定されると、JavaScrpt函数を実行します。その他の場合、リンクに移動します。
1
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
import	com.hangunsworld.net.URLNavigator;
 
var un:URLNavigator = new URLNavigator();
 
btn1.addEventListener(MouseEvent.CLICK, listener);
btn1.num = 0;
btn2.addEventListener(MouseEvent.CLICK, listener);
btn2.num = 1;
btn3.addEventListener(MouseEvent.CLICK, listener);
btn3.num = 2;
 
var xml:XML = 
<sample>
             <link>
                           <link_url><![CDATA[http://hangunsworld.com]]></link_url>
                           <link_target><![CDATA[_self]]></link_target>
             </link>
             <link>
                           <link_url><![CDATA[test2]]></link_url>
                           <link_target><![CDATA[javascript]]></link_target>
             </link>
             <link>
                           <link_url><![CDATA[test^1^2^3]]></link_url>
                           <link_target><![CDATA[javascript]]></link_target>
             </link>
</sample>;
 
 
function listener(e:MouseEvent):void{
	var mc:MovieClip = e.currentTarget as MovieClip;
	var num:uint = mc.num;
 
	var link:String = xml.link[num].link_url.toString();
	var targ:String = xml.link[num].link_target.toString();
 
	un.analyze(link, targ, e.ctrlKey, e.altKey, "^");
}

URLNavigator class.

1
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.

Downloader class was modified.

Downloader 클래스의 패키지를 com.hangunsworld.util 에서 com.hangunsworld.net 으로 변경하였습니다. 아무래도 util 보다는 net 패키지에 있는 것이 더 적당한 것 같아서요.

그리고 addEventListener, removeEventListener 메소드를 추가하여, 다운로드 프로그래스, 완료, 취소 등 이벤트들을 사용할 수 있습니다.

Downloader class has been moved from com.hangunsworld.util to com.hangunsworld.net. I think the net is the appropriate package rather than the util.

And I added addEventListener and removeEventListener methods. Now you can monitor the download progress or get comepete event, and so on.

Downloadクラスを com.hangunsworld.util から com.hangunsworld.net に移動しました。なぜならuitlよりnetクラスの方が相応しそう。

また、addEventListenerとremoveEventListenerメソッドを追加しました。ダウンロードプログレス、完了、キャンセルイベントを含め、色んなイベントを使えます。