flash绑定资源自定义一个按钮
写一个按钮类 package mobile.display {import flash.display.Sprite; import flash.events.MouseEvent; import flash.filters.BitmapFilterQuality; import flash.filters.GlowFilter; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; public class SecSimpleButton extends Sprite{ [Embed(source="resource/button/SimpleButton1_1.png")]? private var simpleButton1_1:Class; [Embed(source="resource/button/SimpleButton1_2.png")]? private var simpleButton1_2:Class; [Embed(source="resource/button/SimpleButton1_3.png")]? private var simpleButton1_3:Class; [Embed(source="resource/button/SimpleButton2_1.png")]? private var simpleButton2_1:Class; [Embed(source="resource/button/SimpleButton2_2.png")]? private var simpleButton2_2:Class; [Embed(source="resource/button/SimpleButton2_3.png")]? private var simpleButton2_3:Class; private static var textFormat:TextFormat; private var skin:SecMovieClip; private var _textf:TextField; private var _type:int; public function SecSimpleButton(text:String="確 定",button_type:int=1){ super(); this.mouseChildren=false; this.cacheAsBitmap=true; this.buttonMode=true; if(button_type==1){ skin=new SecMovieClip(simpleButton1_1,simpleButton1_2,simpleButton1_3); }else{ skin=new SecMovieClip(simpleButton2_1,simpleButton2_2,simpleButton2_3); } this.addChild(skin); _textf=new TextField; _textf.x=0; _textf.y=15; _textf.width=this.width; _textf.height=50; _textf.autoSize=TextFieldAutoSize.CENTER; if(!textFormat){ textFormat=new TextFormat; textFormat.color=0xE4BA9A; textFormat.size=30; textFormat.font='黑體'; } _textf.defaultTextFormat=textFormat; _textf.text=text; this.addChild(_textf); _type=button_type; this.addEventListener(MouseEvent.MOUSE_DOWN,onDown); this.addEventListener(MouseEvent.MOUSE_UP,onUp); this.addEventListener(MouseEvent.MOUSE_OUT,onOut); var glow:GlowFilter = new GlowFilter(0,1,5,1000,BitmapFilterQuality.LOW); _textf.filters=[glow]; } public function setBtnTxt(text:String):void{ _textf.text=text; } public function clear():void{ skin.clear(); this.removeEventListener(MouseEvent.MOUSE_DOWN,onDown); this.removeEventListener(MouseEvent.MOUSE_UP,onUp); this.removeEventListener(MouseEvent.MOUSE_OUT,onOut); } private function onOut(e:MouseEvent):void{ if(skin){ if(_type==2){ skin.width=340; skin.height=70; skin.x=0; skin.y=0; }else{ skin.gotoAndStop(0); } } } private function onDown(e:MouseEvent):void{ if(skin){ if(_type==2){ skin.width=348; skin.height=78; skin.x=-4; skin.y=-4; }else{ skin.gotoAndStop(1); } } } private function onUp(e:MouseEvent):void{ if(skin){ if(_type==2){ skin.width=340; skin.height=70; skin.x=0; skin.y=0; }else{ skin.gotoAndStop(0); } } } public function setUnClick(bUnClick:Boolean=true):void{ if(bUnClick){ this.mouseEnabled=false; skin.gotoAndStop(2); }else{ this.mouseEnabled=true; skin.gotoAndStop(1); } } } } 按钮类中要用到的自定义Bitmap package mobile.display 有了上面两个类,就可以使用自定义的按钮了。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |