비트 맵 클래스 제작 버튼 사용 하기

최근 플래시 를 만 들 때 폭 을 마음대로 설정 할 수 있 는 버튼 구성 요 소 를 만들어 야 합 니 다.버튼 스타일 이 변형 되 지 않도록 버튼 을 여러 mc 로 나 누 는 방법 으로 만 듭 니 다.하지만 사실 버튼 의 동적 효과 에 대한 요구 가 많 지 않 으 면 Bitmap 클래스 로 만 들 수 있 습 니 다.다음은 버튼 의 한 상 태 를 분해 하 는 것 입 니 다.일반적인 아 이 디 어 는 세 개의 MC 로 하 는 것 입 니 다.그리고 폭 을 바 꾸 면 중간 mc 의 폭 을 동적 으로 바 꾸 면 됩 니 다.하지만 이렇게 되면 요소 제작 에 문제 가 있 습 니 다.bitmap 류 를 사용 하면 한 장의 그림 을 세 개의 MC 로 나 누 어 생 성 할 수 있 습 니 다.대량으로 사용 할 때 효율 이 많이 향상 되 었 습 니 다.

방법:

/**
 * date  : 2007.2.6
 * author : Frank
 * site  : http://www.2solo.net/log
 */
import flash.display.*;
import flash.geom.Rectangle;
import flash.geom.Point;
install_img("mT_over_bmp", 200, 158, 5, bmp_mc);
function install_img(image_url, center_width, face_width, bar_left, tar_mc) {
 //image_url:
 //center_width:
 //face_width:
 //bar_left: mc
 //tar_mc:
 ///
 var linkageId:String = image_url;
 var myBD:BitmapData = BitmapData.loadBitmap(linkageId);
 if (tar_mc == undefined || tar_mc == "") {
  tar_mc = this;
 }
 //bmp_mc.attachBitmap(myBD, this.getNextHighestDepth());                                        
 face_width = face_width-2*bar_left;
 /// MC
 tar_mc.center_mc.removeMovieClip();
 tar_mc.left_mc.removeMovieClip();
 tar_mc.right_mc.removeMovieClip();
 var center_mc:MovieClip = tar_mc.createEmptyMovieClip("center_mc", tar_mc.getNextHighestDepth());
 var left_mc:MovieClip = tar_mc.createEmptyMovieClip("left_mc", tar_mc.getNextHighestDepth());
 var right_mc:MovieClip = tar_mc.createEmptyMovieClip("right_mc", tar_mc.getNextHighestDepth());
 center_mc._x = bar_left;
 left_mc._x = 0;
 right_mc._x = center_width-bar_left;
 ///
 var myBD_C:BitmapData = new BitmapData(face_width, myBD.height, true, 0x00FF0000);
 var myBD_L:BitmapData = new BitmapData(bar_left, myBD.height, true, 0x00FF0000);
 var myBD_R:BitmapData = new BitmapData(bar_left, myBD.height, true, 0x00FF0000);
 ///
 myBD_C.copyPixels(myBD, new Rectangle(bar_left, 0, face_width, myBD.height), new Point(0, 0));
 myBD_L.copyPixels(myBD, new Rectangle(0, 0, bar_left, myBD.height), new Point(0, 0));
 myBD_R.copyPixels(myBD, new Rectangle(myBD.width-bar_left, 0, bar_left, myBD.height), new Point(0, 0));
 //
 center_mc.attachBitmap(myBD_C, this.getNextHighestDepth());
 left_mc.attachBitmap(myBD_L, this.getNextHighestDepth());
 right_mc.attachBitmap(myBD_R, this.getNextHighestDepth());
 ///
 center_mc._width = center_width-2*bar_left;
}
stop();

좋은 웹페이지 즐겨찾기