论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash AS编程教程
Tag:2.0,3.0菜鸟,游戏,,cs,技巧,源码,,文本,文字,函数,音乐,随机,拖拽,asp,access,xml,mc,视频教程

可定制界面,可缓冲显示的窗体类

文章类别:Flash AS编程 | 发表日期:2008-10-6 17:36:04


   已经好久没有写as代码了,今天写了一个可定制界面,可缓冲移动位置,可缓冲改变大小的窗体类,采用as2.0方式!同时可以加载外部SWF文件,这次我提供相关源文件,方便大家去研究,也可以在我写的类基础修改也行!如要转载请留下一个原文件地址吧!

//核心代码;

class as.Win extends MovieClip {

    private var tl_mc:MovieClip;
    private var tc_mc:MovieClip;
    private var tr_mc:MovieClip;
    private var cl_mc:MovieClip;
    private var cc_mc:MovieClip;
    private var cr_mc:MovieClip;
    private var bl_mc:MovieClip;
    private var bc_mc:MovieClip;
    private var br_mc:MovieClip;
    private var title_txt:TextField;
    private var content_mc:MovieClip;
    private var load_mc:MovieClip;
   //------------------------------------------------;
    private var width:Number;
    private var height:Number;
    //------------------------------------------------;
    private var move_mar:Number;
    private var size_mar:Number;
    private var speed:Number; 
    private var _ddw:Number;
    private var _ddh:Number;
    private var _ddx:Number;
    private var _ddy:Number;
    //------------------------------------------------;
    function Win() {
        this.setSize(200, 100);
        this.move(this._x, this._y);
        this.setSpeed(5);
        this.setTitle("无标题");
   }
   public function setSize(w:Number, h:Number):Void {
        clearInterval(this.size_mar);
        w = Math.max(w, this.tl_mc._width+this.tr_mc._width);
        this.width = Math.max(w, this.bl_mc._width+this.br_mc._width);
        this.height = h;
        this.draw(this.width, this.height);
  }
   public function getWidth():Number {
        return this.width;
   }
   public function getHeight():Number {
        return this.height;
   }
   public function setTitle(title:String):Void{
        this.title_txt.text = title;
   }
   public function loadSwf(url:String):Void{  
  this.content_mc = this.createEmptyMovieClip("hand_mc",5);
  this.content_mc._x = this.cc_mc._x;
  this.content_mc._y = this.cc_mc._y;
  this.content_mc.loadMovie(url);
 }
 public function removeSwf():Void{
  this.content_mc.removeMovieClip();
 }
 private function draw(w:Number, h:Number):Void {
  this.tl_mc._x = this.cl_mc._x=this.bl_mc._x=0;
  this.tl_mc._y = this.tc_mc._y=this.tr_mc._y=0;
  this.tc_mc._x = this.tl_mc._x+this.tl_mc._width;
  this.tc_mc._width = w+this.cl_mc._width+this.cr_mc._width-this.tl_mc._width-this.tr_mc._width;
  this.title_txt._x = this.tc_mc._x;  
  this.title_txt._width = this.tc_mc._width;
  this.tr_mc._x = this.tc_mc._x+this.tc_mc._width;
  this.cl_mc._y = this.cc_mc._y=this.cr_mc._y=this.tl_mc._y+this.tl_mc._height;
  this.cl_mc._height = this.cc_mc._height=this.cr_mc._height=h;
  this.cc_mc._x = this.cl_mc._x+this.cl_mc._width;
  this.cc_mc._width = w;
  this.cr_mc._x = this.cc_mc._x+this.cc_mc._width;
  this.bl_mc._y = this.bc_mc._y=this.br_mc._y=this.cl_mc._y+this.cl_mc._height;
  this.bc_mc._x = this.bl_mc._x+this.bl_mc._width;
  this.bc_mc._width = w+this.cl_mc._width+this.cr_mc._width-this.bl_mc._width-this.br_mc._width;
  this.br_mc._x = this.bc_mc._x+this.bc_mc._width;
 }
 public function setSpeed(speed:Number):Void {
  this.speed = speed;
 }
 public function moveSize(w:Number,h:Number,showed:Boolean):Void {
  if(showed == undefined){
   showed = false;
  }
  w = Math.max(w, this.tl_mc._width+this.tr_mc._width);
  this._ddw = Math.max(w, this.bl_mc._width+this.br_mc._width);
  this._ddh = h;
  this.content_mc._visible = showed;
  clearInterval(this.size_mar);
  this.size_mar = setInterval(this, "moveSizeAction", 50);
 }
 private function moveSizeAction() {
  var dw:Number = this.cc_mc._width - this._ddw;
  var dh:Number = this.cc_mc._height - this._ddh; 
  var ow:Number = dw/this.speed;
  var oh:Number = dh/this.speed;  
  this.draw(this.cc_mc._width-ow,this.cc_mc._height-oh);
  if(Math.abs(dw)<1 && Math.abs(dh)<1){
   this.content_mc._visible = true;   
   this.setSize(this._ddw,this._ddh);
  }
 }
 public function moveTo(x:Number,y:Number):Void {  
  this._ddx = Math.round(x);
  this._ddy = Math.round(y);
  clearInterval(this.move_mar);
  this.move_mar = setInterval(this, "moveToAction", 50);
 }
 private function moveToAction() {
  var dx:Number = this._x - this._ddx;
  var dy:Number = this._y - this._ddy; 
  var ox:Number = dx/this.speed;
  var oy:Number = dy/this.speed;
  this._x -= ox;
  this._y -= oy;
  if(Math.abs(dx)<1 && Math.abs(dy)<1){
   this.move(this._ddx,this._ddy);
  }
 }
 public function move(x:Number, y:Number):Void {  
  this._x = Math.round(x);
  this._y = Math.round(y);
  clearInterval(this.move_mar);
 }
}
/upimg/soft/1_061231090156.rar
上一篇:{实例}游戏设计原理 人气:3426
下一篇:{实例}游戏代码编写 人气:2005
视频教程列表
文章教程搜索
 
Flash AS推荐教程
Flash AS热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058