Archive for the ‘AS3’ Category

Runtime font sharing.

Thursday, July 3rd, 2008
우선 공유하려는 폰트를 라이브러리에 등록하고, 아래 그림과 같이 설정한 다음 SWF을 퍼블리시 합니다.
First, register a font in the library, and set the linkage properties like the following image. Then, publish the SWF file.
まず、共有しようとするフォントをライブラリに登録し、下のイメージのように設定して、SWFファイルを出版します。

Sharing a font

이 SWF파일을 Loader 객체로 로드한 다음, 아래 코드를 사용하여 공유된 폰트를 등록, 사용할 수 있습니다.
Load the SWF via Loader object, then you can retrieve the shared font from the loaded SWF.
このSWFファイルをLoader客体を通じてロードした後で、次のコードを使って、共有されたフォントを登録し、使用できます。
var sharedFont:Class = font_loader.contentLoaderInfo.applicationDomain.getDefinition("Gothic") as Class;
Font.registerFont(sharedFont);

Using the shared font.

그러나 여기서 한 가지 문제가 있습니다. 같은 도메인의 경우 상관이 없으나, 서로 다른 도메인에서는 SWF가 로드되었다 하더라도, ApplicationDomain.getDefinition() 메소드를 통해 폰트를 가져올 수 없습니다. 즉, www.mydomain.com의 SWF에서 font.mydomain.com의 SWF파일에 정의된 폰트를 사용할 수 없다는 것입니다.

이 문제를 해결하기 위해서는 LoaderContext.securityDomain 속성을 사용하여, 다른 도메인의 SWF 사이에서 자원에 대한 접근을 허용할 필요가 있습니다. 다음의 코드는 LoaderContext를 사용하여 다른 도메인 사이에 폰트를 공유할 수 있도록 구성한 것입니다.

But there is a problem. If the two SWF files is on the same domain, no problem. If the SWFs are seperated in different domains, you can not access to the shared font with ApplicationDomain.getDefinition() method, though the SWF file is loaded in. So, an SWF file on www.mydomain.com can not use a font in an SWF on font.mydomain.com.

You can use LoaderContext property, to allow access to assets in a different domain’s SWF file. The following code shows how it works.

でも、一つ、問題があります。同じドメインなら問題ないが、二つのSWFファイルが違うドメインにあると、そのSWFをロードしても、ApplicationDomain.getDefinition()メソッドを使って共有フォントにアクセスすることが出来ないんです。

この問題を解決するために、LoaderContext.securityDomain属性を設定して、他のドメインにあるSWFファイルの資源にアクセスを許容しなければなりません。次のコードは、LoaderContextを使用して、違うドメインからフォントを共有しに作成したものです。

(more…)

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!