返回织梦建站服务网首页 业界新闻 教程文档 资源下载 酷站鉴赏 免费服务 站长工具
织梦建站工作室
织梦建站论坛
载入中…
专题栏目
最新热门
>>更多热门...  
最新推荐
>>更多推荐...  
  您现在的位置: 织梦建站服务网 >> 建站教程 >> WEB多媒体 >> Flash >> 教程正文
巧用Bitmap类制作按钮          
HITS: TIME:2007-4-27 9:58:28 AUTHOR:frank URL:蓝色理想
CONTENT INTRODUCE :
放大文字  缩小文字  发表评论  加入站内收藏夹  告诉好友  打印模式  关闭窗口 

最近在制作flash时需要制作一个可以随意设定宽度的按钮组件.为了保证按钮样式不变形,一般都会采用将按钮分成几个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();

教程录入:jerome    责任编辑:jerome 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口

    相关教程
    Apollo已经悄然降临?
    AS2高级绘图工具类下载
    探索F9 As3.0 Preview
    FLASH AS实现马赛克效果
    Flash渐进填充调试及个人感想
    ActionScript 3.0 概要
    巧用XML做多语言界面的FLASH
    Flash 中响应键盘的一般方法
    三维全景的行业应用
    Flash MX 2004 video
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    湘ICP备05010790号 {$Wap}
    关于我们 | 版本历史 | 联系方法 | 隐私条例 | 链接我们 | 广告服务 | 常见问题 | 友情链接 | 网站公告 | 设为首页 | 收藏本站
    Copyright © 2001-2006 17zm.NET All Rights Reserved.  织梦建站工作室[织梦建站工作室]™荣誉出品. Since 2001