• 【设为首页】
  • 【收藏闪客居】
当前位置:主页>FLASH AS 编程>AS基础篇>AS 3.0>文章内容
  • 一个用as3模拟as2的MovieClip类
  • 来源:dayu的Blog 作者:dayu 2008-05-05 【

这个类比较简单,不习惯as3可视化类的同学可以试试

使用方法很简单,所有可视化类都可以继承自该类。

比如文档类继承这个类,可以用

this.attachMovie(可视化类名,实例名);来创建影片剪辑

然后就可以用 this.实例名引用那个剪辑了

 this.removeMovie(可视化类名,实例名);来删除影片剪辑

是不是和as2的很一样呢。

package{
    import flash.display.DisplayObject;   
    import flash.display.Sprite;
    /**
     * @author dayu
     * @deprecated 本类是为了纪念as2而存在,对于怀念as2的同学,
     * 使用本类。将让你感到一种亲切感
     *
     */
    dynamic public class EmptyMovie extends Sprite {
        var pen:Pen;
        public function EmptyMovie() {
            super();
            pen=new Pen();
        }
        public function attachMovie(cl:Class,nam:String) {
            this[nam]=new cl();
           
            this.addChild(this[nam]);
            return this[nam];
        }
        public function removeMovie(nam:String){
            this.removeChild(this[nam]);
            delete this[nam];
        }
        //设定笔刷相关
        public function setpen(thickness,color,alpha){
            this.pen.thickness=thickness;
            this.pen.color=color;
            this.pen.alpha=alpha;
            this.graphics.lineStyle(pen.thickness,pen.color,pen.alpha);
        }
        public function resetpen(){
            this.graphics.lineStyle(pen.thickness,pen.color,pen.alpha);
        }
        public function setbrush(color){
            this.graphics.beginFill(color,1);
        }
        //设定绘图相关
        public function clear(){
            this.graphics.clear();
        }
        public function beginFill(color:uint){
            this.graphics.beginFill(color);
        }
        public function endFill(){
            this.graphics.endFill();
        }
        public function drawCircle(x, y, radius){
            this.graphics.drawCircle(x, y, radius);
        }
        public function drawEllipse(x, y, width, height){
            this.graphics.drawEllipse(x, y, width, height);
        }
        public function drawRect(x, y, width, height){
            this.graphics.drawRect(x, y, width, height);
        }
        public function drawRoundRect(x, y, width, height, ellipseWidth, ellipseHeight){   
            this.graphics.drawRoundRect(x, y, width, height, ellipseWidth, ellipseHeight);
        }
        public function lineTo(x, y){
            this.graphics.lineTo(x, y);
        }
        public function moveTo(x, y){
              this.graphics.moveTo(x, y);
        }
    }
}
class Pen extends Object{
    public var thickness:int;
    public var color:uint;
    public var alpha:Number;
    function Pen(thick=2,col=0xffffff,a=1){
        thickness=thick;
        color=col;
        alpha=a;
    }
    public function clone(pen:Pen):Pen{
        return new Pen(thickness,color,alpha);
    }
}

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://dayuhome.blogbus.com/logs/19388127.html





上一篇:a.swf与加载的swf的通讯方法(as3.0)   下一篇:一个用as3模拟as2的MovieClip类
您的评论
  • 用户名:新注册) 密码: 匿名评论
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)

Copyright © 2006-2008 flashas.net All Rights Reserved.
网站内容咨询: admin#flashas.net (#为@) 联系QQ:40777822 浙ICP备06033001号
(本网站最佳浏览解析度为1024*768, 建议使用IE 6.0或以上版本浏览器。)