I made an effect similar to the paint bucket feature in Photoshop. This replace colors similar to a user defined color with a specific color.

You can download the BMPFunctions.as file in the following link.

포토샵의 페인트 버켓 툴과 비슷한 효과를 만들어 보았습니다. 지정된 색과 비슷한 색상을 찾아서 원하는 색상으로 바꿔줍니다.

클래스 파일은 아래 페이지에서 BMPFunctions.as를 다운로드하면 됩니다.

PhotoshopのPaint Bucketのような物を作ってみました。選んだ色に似ている色をほかの色に変わります。

下のリンクのページで BMPFunctions.asファイルをダウンロードできます。

http://hangunsworld.com/classes/com/hangunsworld/as3/util/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import com.hangunsworld.as3.util.BMPFunctions;
 
var bd:BitmapData = new BitmapData(mc.width, mc.height, true, 0×00000000);
bd.draw(mc);
 
var bmp:Bitmap = new Bitmap(bd);
addChild(bmp);
bmp.x = mc.width;
 
// Replace Color button event listener
replace_btn.addEventListener(MouseEvent.CLICK, doReplace);
function doReplace(evt:MouseEvent):void{
	var c1:uint = uint(“0x” + c1_txt.text);
	var c2:uint = uint(“0x” + c2_txt.text);
	var t:uint = Math.max(0, Math.min(255, uint(t_txt.text)));
	t_txt.text = t.toString();
 
	// draws original image
	bd.draw(mc);
	// replaces colors
	bd = BMPFunctions.replaceColor(bd, c1, c2, t);
}

Download FLA

 
Flickr changes its cross domain policy and allows Flash applications to load images from Flickr server and to modify bitmap data of the images. The new cross domain ploicy file(http://static.flickr.com/crossdomain.xml) lets Flash applications on any servers to access Flickr images.
Before the change, you can load images from Flickr server. But, you can not access the bitmap data of the images and can not make bitmap data using BitmapData.draw() method. Now, it is possible.

To access the bitmap data, you have to set LoaderContext.checkPolicyFile to true.

플리커가 플래시 어플리케이션에서 플리커의 이미지를 로드하는 것은 물론 비트맵데이터도 제어가 가능하도록 크로스 도메인 정책을 오픈하였습니다. 새로운 크로스 도메인 정책 파일(http://static.flickr.com/crossdomain.xml)은 모든 서버의 플래시 어플리케이션에서 접근이 가능하도록 바뀌었습니다.
이전에는 이미지를 로드하더라도, 비트맵데이터를 가공하거나 BitmapData.draw() 메소드를 이용하여 이미지를 비트맵데이터로 변환할 수 없었지만, 이제 가능하게 되었습니다.

그러나 다른 서버로 부터 로드된 이미지를 가공하려면, 다음과 같이 AS3에서 LoaderContext.checkPolicyFile 설정을 해주어야 합니다.

Flickrはクロスドメイン政策を変更して、フラッシュアプリケ―ションがFlickrサ―バ―のイメージをダウンロードしてBitmapDataを改めることができました。新たなクロスドメイン政策ファイル(http://static.flickr.com/crossdomain.xml)はあらゆるサーバーからのアクセスを許します。
以前には、Flickrサーバーからイメージをロードしても、BitmapDataを修正することとBitmapData.draw()メソッドを使ってBitmapDataを作ることはできなかった。今なら出来ます。

BitmapDataにアクセスするためには、LoaderContext.checkPolicyFile設定をしなければならないんです。

1
2
3
4
public var context:LoaderContext;
context = new LoaderContext();
context.checkPolicyFile = true;
loader.load(loaderUR, context);

via Flickr: Now Even More Flash-friendly

 
You can pass data from an HTML document to a Flash movie via FlashVars or query string.
In AS2, these data are defined as variables in the main timeline(_root). But you have to access the data using loaderInfo.parameters in AS3.
HTML문서에서 FlashVars 또는 쿼리 스트링을 사용하여 플래시 무비로 데이터를 전달할 수 있습니다.
AS2에서는, 이렇게 넘어온 데이터가 메인 타임라인(_root) 상의 변수로 만들어집니다. 그러나 AS3에서는, loaderInfo.parameters를 통하여 접근하게 됩니다.
FlashVarsおよびquery stringを使ってHTMLドキュメントからFlashム―ビ―にデ―タを伝える事が出来ます。
AS2では、そのデーターがメーンのタイムライン(_root)の変数に作られます。しかし、AS3ではloaderInfo.parametersを使う事になりました。
1
2
var userID:String = loaderInfo.parameters.userID;
var pathXML:String = loaderInfo.parameters.pathXML;
 
Some methods newly added to Array calss in AS3 will save time to code “for” loops.
Adobe should have introduced them earlier…
AS3의 Array 클래스에 새로운 메소드들이 등장하면서 for 루프 돌리는 일이 많이 줄어들 것 같네요 ^^
더 빨리 나왔어야 했는데…

every(callback:Function, thisObject:* = null):Boolean
Executes a test function on each item in the array until an item is reached that returns false for the specified function.

some(callback:Function, thisObject:* = null):Boolean
Executes a test function on each item in the array until an item is reached that returns true.

filter(callback:Function, thisObject:* = null):Array
Executes a test function on each item in the array and constructs a new array for all items that return true for the specified function.

forEach(callback:Function, thisObject:* = null):void
Executes a function on each item in the array.

indexOf(searchElement:*, fromIndex:int = 0):int
Searches for an item in an array by using strict equality (===) and returns the index position of the item.

lastIndexOf(searchElement:*, fromIndex:int = 0x7fffffff):int
Searches for an item in an array, working backward from the last item, and returns the index position of the matching item using strict equality (===).

quote from ActionScript 3.0 Language and Components Reference

 
1
2
3
4
for(var i:uint=0; i<numChildren; i++){
	var mc:MovieClip = getChildAt(i);
	trace(mc.x, mc.y);
}
This code causes the type mis-match error at compile, because getChildAt() method returns a DisplayObject.
위 코드는 컴파일 시에 다음과 같은 타입 미스매치 에러를 냅니다. 왜냐하면 getChildAt()메소드는 DisplayObject 객체를 리턴하기 때문이죠.

1118: Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type flash.display:MovieClip.

To avoid the compile error, you can cast the returned value as MovieClip like this.
이러한 컴파일 에러를 회피하기 위해 다음과 같이 리턴된 값을 MovieClip로 캐스팅합니다.
1
var mc:MovieClip = MovieClip(getChildAt(i));
You can also use “as”.
또는 “as”를 사용할 수 있습니다.
1
var mc:MovieClip = getChildAt(i) as MovieClip;
© 2011 Hangun's World - Blog Suffusion theme by Sayontan Sinha