flash as3做几何画板-先写一个按钮类


package draw1
{
   import flash.display.MovieClip;
   import flash.display.Sprite;
   import flash.events.MouseEvent;
//按钮类
   public class draw_button extends MovieClip {
////////////////////////////////////////////////////////////////
//hit:能接受鼠标输入的区域
//sel:本按钮是否已经被选中
//
////////////////////////////////////////////////////////////////

 var hit:Sprite=new Sprite();
 var sel:Boolean =new Boolean();
////////////////////////////////////////////////////////////////
//
//函数名:draw_button//

//说明:  用来构建按钮
////////////////////////////////////////////////////////////////
 public function draw_button(){
  this.buttonMode = true;
  this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener);
  this.addEventListener(MouseEvent.MOUSE_UP, mouseUpListener);
  update();
  //添加事件

  this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener);
  this.addEventListener(MouseEvent.MOUSE_UP, mouseUpListener);
  }
 private function mouseDownListener(evt:MouseEvent){
  if (this.sel==false){
   update(2);
   }else{
   update();
   }
  }
 private function mouseUpListener(evt:MouseEvent){
  for (i=1;i
//设置按钮是否被选中
 public function setSel(select:Boolean ){
  this.sel=select;
  }
//获取当前按钮的焦点状态
 public function getSel():Boolean {
  return this.sel;
  }
//更新显示按钮,粗边框/细边框
 public function update(lStyle:Number=0){
  if (lStyle==0){
   this.sel=false;
   }else{
   this.sel=true;
   }
  hit.graphics.clear();
  hit.graphics.beginFill(0x888888,0.08);
  hit.graphics.lineStyle(lStyle);
  hit.graphics.drawRect(0,0,23.5,23.5);
  hit.graphics.endFill();
  this.addChild(hit);
  }
 }
}
本文转自:http://www.5uflash.com/flashjiaocheng/Flash-as3-jiaocheng/1944.html

你可能感兴趣的:(html,Flash,UP)