Posts Tagged ‘AS3’

Tworld, Menu Style UP open.

Sunday, August 10th, 2008

작년부터 시작해서 1년 가까이 진행해온 Tworld의 휴대전화 메뉴 꾸미기, 메뉴 스타일 UP이 오픈했습니다. 이전에 개발했던 싸이월드의 아이쿠킹이나 편집스킨과 비슷한 맥락의 어플리케이션으로, 휴대전화의 메뉴를 사용자가 마음대로 꾸밀 수 있도록 한 서비스 입니다.

Tworld 홈페이지의 폰메뉴 만들기 어플리케이션에서 자유롭게 메뉴를 꾸밀 수 있고, CP 업체에서 제공한 메뉴를 다운로드 하거나, 편집할 수도 있습니다.

오랜 기간동안 개발하면서 많이 고생하신 SKT, 어도비, ALOX 외에도 많은 업체의 관계자 분들이 있어서 무사히 서비스를 오픈할 수 있었습니다.

URLNavigator class.

Friday, April 4th, 2008
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.

Friday, April 4th, 2008
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メソッドを追加しました。ダウンロードプログレス、完了、キャンセルイベントを含め、色んなイベントを使えます。

Saving an image with AS3 and PHP: 3. ByteArray

Monday, January 14th, 2008

The following ActionScript 3 code is used to save GIF image that is encoded using GIFEncoder. I use GIFEncoder, distributed via ByteArray.org, to encode GIF files.
다음은 GIFEncoder를 이용하여 인코딩한 GIF 파일을 저장하는 액션스크립트3 코드입니다. GIF 파일을 인코딩하기 위해서, ByteArray.org에서 배포하는 GIFEncoder를 사용하였습니다.
これはGIFEncoderを使用してGIFファイルを保存するActionScript3のコードです。GIFファイルをエンコードするために、ByteArray.comで配布されているGIFEncoderを使いました。
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
71
72
73
74
75
76
77
78
79
80
81
82
// Imports the GIFEndocer class by Thibault Imbert.
// You can download it from ByteArray.org.
import org.gif.encoder.GIFEncoder;
 
var serverPath:String = "/";
 
// Initializes GIFEncoder
var myGIFEncoder:GIFEncoder = new GIFEncoder();
myGIFEncoder.setRepeat(0);
myGIFEncoder.setDelay (300);
 
// Initializes an URLLoader object to upload a file stream.
var ul:URLLoader = new URLLoader();
ul.addEventListener(Event.COMPLETE, saveDone);
 
var urh:URLRequestHeader = new URLRequestHeader("Accept","image/gif");
var BOUNDARY:String = "---------------------------7d76d1b56035e";
 
/**
 * Starts the gif encoding when clicks on the stage.
 */
stage.addEventListener(MouseEvent.CLICK, generateGIF);
function generateGIF(evt:MouseEvent):void{
 
	// Starts the gif encoder.
	myGIFEncoder.start();
 
	// Add frame.
	var bd:BitmapData = new BitmapData(100, 100, false, Math.round(0xFFFFFF*Math.random()));
	myGIFEncoder.addFrame(bd);
 
	// Finishes the gif encoder.
	myGIFEncoder.finish();
 
	// Starts the upload process.
	uploadGIF();
 
}// end generateGIF
 
/**
 * Generates a file stream and upload it.
 */
function uploadGIF():void{
 
	// Retrieves the file stream from the GIF Encoder.
	var myGIFStream:ByteArray = myGIFEncoder.stream;
	var filename:String = "test.gif";
 
	// Creates the file header.
	var formData:String  =  "--" + BOUNDARY + '\r\nContent-Disposition: form-data; name="Filedata"; filename="' + filename + '"\r\nContent-Type: application/octet-stream\r\n\r\n';
	var formData2:String = "\r\n";
	formData2 += "--" + BOUNDARY + '\r\nContent-Disposition: form-data; name="Filedata"\r\n\r\nSubmit Query\r\n';
	formData2 += "--" + BOUNDARY + '--';
 
 
	// Conbines the header and the file stream.
	var dataArray:ByteArray = new ByteArray();
	dataArray.writeMultiByte(formData,"ascii");
	for(var k:uint=0; k<myGIFStream.length; k++){
		dataArray.writeByte(myGIFStream[k]);
	}	
	dataArray.writeMultiByte(formData2,"ascii");
 
	// Initializes an URLRequest object
	var ur:URLRequest = new URLRequest();
	ur.requestHeaders.push(urh);
	ur.method = URLRequestMethod.POST;
	ur.contentType = "multipart/form-data; boundary=" + BOUNDARY;
	ur.url = serverPath + "test/uploadok.php";
	ur.data = dataArray;
 
	ul.load(ur);
 
}// end uploadGIF
 
/**
 * Executes when a file upload is finished.
 */
function saveDone(evt:Event):void{
	var str:String = evt.target.data;
	trace(str);
}// end saveDone
Special thanks to Kim Eung. He devised the draft of the PHP and AS3 codes. Furthermore, he allowed me to open them to the public.
이 PHP와 AS3 코드의 기틀을 만들고, 이 소스를 공개하는데 흔쾌히 동의하신, 김응 실장님에게 진심으로 감사드립니다.

Saving an image with AS3 and PHP: 2. FileReference

Friday, January 4th, 2008

The following code is an ActionScript 3.0 code that uploads files via FileReference.
다음은 FileReference를 이용하여 파일을 업로드하는 액션스크립트3 코드입니다.
Sorry, Japanese translation is not yet available.
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
var serverPath:String = "/";
 
// Creates a FileReference object.
var fr:FileReference = new FileReference();
var frFilter:FileFilter = new FileFilter("JPGs", "*.jpg");
 
// Adds events to the FileReference object.
fr.addEventListener(Event.SELECT, fileSelected);
fr.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, fileUploaded);
fr.addEventListener(ProgressEvent.PROGRESS, fileProgress);
fr.addEventListener(IOErrorEvent.IO_ERROR, errorOccured);
 
 
/**
 * Executes when a user selects a file to upload.
 */
function fileSelected(evt:Event):void{
 
	// Checks the size of the file.
	if(fr.size > 200*1024){
		trace("You can NOT upload an image lagerer than 200KB.");
	}else{
		var ur:URLRequest = new URLRequest();
		ur.url = serverPath + "test/uploadok.php";
 
		// Puts newName parameter, to avoid the multi-byte filename problem.
		var uv:URLVariables = new URLVariables();
		uv.newName = "upload.jpg";
 
		ur.data = uv;
 
		// Starts uploading.
		fr.upload(ur);
	}// end if else [fr.size]
 
}// end fileSelected
 
 
/**
 * Executes when a file upload is finished.
 */
function fileUploaded(evt:DataEvent):void{
	trace(evt.data);
}// end fileUploaded
 
/**
 * Executes while uploading a file.
 */
function fileProgress(evt:ProgressEvent):void{
	//trace(evt.bytesLoaded + " / " + evt.bytesTotal);
}// end fileProgress
 
/**
 * Executes when an IO error occurs.
 */
function errorOccured(evt:IOErrorEvent):void{
	trace("IO error has occured.");
}// end errorOccured
 
 
/**
 * Shows the file browser when clicks on the stage.
 */
stage.addEventListener(MouseEvent.MOUSE_DOWN, clicked);
function clicked(evt:MouseEvent):void{
	fr.browse([frFilter]);
}
In line 27 through 30, I assign newName parameter to an URLVariables object. This is to avoid IO error which occurs if the filename contains 2-byte characters. If you let the serverscript rename the uploaded file, this is not needed.
27-30번째 줄을 보면, URLVariables 객체에 newName 파라메터를 설정했습니다. 이것은 파일명에 한글과 같은 2바이트 문자가 포함된 경우 서버에서 파일 저장시에 IO 에러가 발생하기 때문에, 이를 피하기 위해서 newName에 별도의 파일명을 저장한 것입니다. 만약 서버측에서 파일명을 변경하도록 구성되어 있다면, 이 부분은 필요 없습니다.
27
28
29
30
var uv:URLVariables = new URLVariables();
uv.newName = "upload.jpg";
 
ur.data = uv;