巧用Bitmap類制作按鈕
最近在制作flash時(shí)需要制作一個(gè)可以隨意設(shè)定寬度的按鈕組件.為了保證按鈕樣式不變形,一般都會(huì)采用將按鈕分成幾個(gè)mc的方法來(lái)制作.但其實(shí),如果對(duì)按鈕的動(dòng)態(tài)效果要求不多的話,完全可以使用Bitmap類來(lái)制作.下面是將按鈕的一個(gè)狀態(tài)分解開來(lái).一般的思路是做為三個(gè)MC,然后在改變寬度是,動(dòng)態(tài)改變中間mc的寬度就可以了。但是這樣的話,對(duì)于元素的制作就比較麻煩.使用bitmap類可以直接將一張圖片分為三個(gè)MC后生成.在批量使用時(shí),效率提高了不少.
方法:
/**
* 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:目標(biāo)圖片路徑
//center_width:整體寬度
//face_width:初始位圖寬度
//bar_left:邊側(cè)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;
///新建圖片數(shù)據(jù)
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());
///調(diào)整距離
center_mc._width = center_width-2*bar_left;
}
stop();
相關(guān)文章
在網(wǎng)頁(yè)中怎樣給已發(fā)布的Flash添加鏈接的方法
說(shuō)到這個(gè)問(wèn)題,可能有人就會(huì)說(shuō),那還不簡(jiǎn)單,直接用flash的ActionScript中的url方法不就搞定了,那么如果我們的UI人員設(shè)計(jì)完flash,但flash對(duì)應(yīng)的鏈結(jié)還沒(méi)有確定或者以后會(huì)變更怎么辦?2007-03-03ActionScript3禁止構(gòu)造請(qǐng)求標(biāo)頭Referer
ActionScript3禁止構(gòu)造請(qǐng)求標(biāo)頭Referer...2007-03-03