Archive for the ‘Flash’ Category

To get the last day of a month.

Wednesday, June 25th, 2008
Anybody who made a calendar in Flash may have written this code. You may use if or switch statements to get the last day of a month.
달력 같은 걸 만들면서 누구나 한번쯤 만들어 봤을 코드입니다. 지정된 달의 마지막 날을 구하기 위해서 if문이나 아래 코드처럼 switch문을 사용하게 되죠.
カレンダーみたいなものを作って見た方は、このコードを作成したことがあるんですね。普通、月の末日を得るために、if文とかswitch文を使うんです。
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
function getLastDayOld(day:Date):Date{
 
	var dd:uint = 31;
 
	var yyyy:uint = day.getFullYear();
	var mm:uint = day.getMonth() + 1;
 
	switch(mm){
 
		case 4:
		case 6:
		case 9:
		case 11:
			dd = 30;
		break;
 
		case 2:
			if((yyyy % 4) == 0 || (yyyy % 100) == 0){
				dd = 29;
			}else{
				dd = 28;
			}
		break;
 
	}
 
	var lastDay:Date = new Date(yyyy, (mm-1), dd);
	return lastDay;
 
}
I figured out a more simple solution. Date.setMonth() method simply gets the job done.
그런데 이 문제를 매우 간단히 해결할 수 있는 코드를 생각해 냈습니다. Date.setMonth() 메소드 하나로 쉽게 처리가 되네요.
これをもっと簡単に処理するコードを考えてみました。Date.setMonth()メソッドを使えば、オーケーです。
1
2
3
4
5
function getLastDay(day:Date):Date{
	var lastDay:Date = new Date(day);
	lastDay.setMonth(lastDay.getMonth() + 1, 0);
	return lastDay;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var day:Date = new Date(2008, 0, 15);
for(var i:uint=0; i<12; i++){
	day.setMonth(i);
	trace((day.getMonth() + 1), " - ", getLastDay(day).getDate(), " : ", getLastDayOld(day).getDate());
}
/* output
1  -  31  :  31
2  -  29  :  29
3  -  31  :  31
4  -  30  :  30
5  -  31  :  31
6  -  30  :  30
7  -  31  :  31
8  -  31  :  31
9  -  30  :  30
10  -  31  :  31
11  -  30  :  30
12  -  31  :  31*/

URLNavigator has been modified.

Tuesday, June 17th, 2008
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, "^");
}

Bitmap.bitmapData sets smoothing to false.

Monday, June 9th, 2008

Bitmap.bitmapData 속성을 통해서 비트맵 이미지를 교체하는 경우 스무딩 속성이 false로 변경되어 버립니다. Bitmap(bd, “auto”, true); 처럼 비트맵 객체를 생성할 때 스무딩을 true로 설정하였다 하더라도, bitmapData 속성을 변경하면, smothing 속성이 무조건 false로 바뀝니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var bd1:BitmapData = new BitmapData(300, 225);
bd1.draw(mc, null, null, null, null, true);
 
var bmp1:Bitmap = new Bitmap(bd1, "auto", true);
var bmp2:Bitmap = new Bitmap(bd1, "auto", true);
 
addChild(bmp1);
addChild(bmp2);
 
bmp1.y = bmp2.y = -50;
bmp1.x = 50;
bmp2.x = 350;
bmp1.rotation = bmp2.rotation = 30;
 
bmp2.bitmapData = bd1;

그러므로 bitmapData 속성을 변경하면, 다음과 같이 smoothing 속성을 다시 true로 설정해 주어야 합니다.

16
bmp2.smoothing = true;

Link about SWF Encryption.

Thursday, May 29th, 2008
지난 플래시 액션스크립트 카페 2차 컨퍼런스의 문답시간에 얘기했던 SWF 파일 암호화와 관련된 사이트 주소입니다.
SWF 파일의 암호화는 자바 프로그램을 이용하고, 암호화된 SWF 파일을 로드하여 복원하는 부분에서 AS3의 바이트어레이를 사용합니다.
The following link is the post about SWF Ecnryption, I mentioned at the Q&A session of the 2nd FASC conference. The container SWF file loads an encrypted SWF file, encrypted using Java application, and then decrypts the file using ByteArray in AS3.
Flash ActionScript Cafe’s Conferenceで話した、SWFファイルの暗号化に関するウェブサイトです。
Javaアップリケーションを使ってSWFファイルを暗号化し、AS3でByteArrayを使用してそのSWFを解読します。

Soph-Ware Associates | Blog - Why Obfuscate, Encrypt those SWFs!

Image Editor Source Code

Monday, May 26th, 2008
지난 토요일, 제2회 플래시 액션스크립트 카페 컨퍼런스에서 발표한 이미지 에디터의 소스 파일입니다.
Here goes the source files of the Image Editor, I have presented at the 2nd FASC Conference last Saturday.
先週の土曜日、二回目のFASC Conferenceで発表したイメージエディタのソースコードです。

Download the source files.

Preview the sample movie.