论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: 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教程
Tag:flash cs,flash 8,鼠绘,as,手绘,工具,文字,loading,入门,初学,mc,影片剪辑,声音,mtv,游戏,引导,遮罩,菜单,补间,广告条,时钟,视频教程

动态画sin和它的移动

文章类别:Flash | 发表日期:2008-9-21 20:10:00

  

好久未发帖了,刚才看到有人问到画sin后怎样移动所画的曲线,现举一小例,抛砖引玉... 

效果如下:(并附源文件)

/UploadTeach/200711/2007112215613785.swf
源文件: 画sin.rar

以下代码直接拷贝到帧上就行了:

// x0 y0 起点坐标 |  k 垂直幅度  |  disX 水平幅度  disY  周期   |   i  速度变量
var x0:Number = 100, y0:Number = 200, k:Number = 100, disX:Number = 2, disY:Number = 1, i:Number = 0;
//===  画水平线背景  =======================
drawViewX();
function drawViewX() {
        // wh 单元格长与宽  
        var wh:Number = 10;
        this.createEmptyMovieClip("lineX", this.getNextHighestDepth());
        onEnterFrame = function () {
                with (lineX) {
                        lineStyle(1, 0xCCCCCC, 100);
                        moveTo(0, wh);
                        lineTo(Stage.width, wh);
                }
                if (lineX._width>=Stage.width) {
                        wh += 10;
                }
                if (wh>=Stage.height) {
                        delete onEnterFrame;
                        drawViewY();
                }
                updateAfterEvent();
        };
}
//===  画垂线背景  =========================
function drawViewY() {
        // wh 单元格长与宽  
        var wh:Number = 10;
        this.createEmptyMovieClip("lineY", this.getNextHighestDepth());
        onEnterFrame = function () {
                with (lineY) {
                        lineStyle(1, 0xCCCCCC, 100);
                        moveTo(wh, 0);
                        lineTo(wh, Stage.height);
                }
                if (lineX._width>=Stage.height) {
                        wh += 10;
                }
                if (wh>=Stage.width) {
                        delete onEnterFrame;
                        drawX();
                }
                updateAfterEvent();
        };
}
//========  画sin主函数   ======================
function drawSin() {
        this.createEmptyMovieClip("line", this.getNextHighestDepth());
        with (line) {
                lineStyle(2, 0x000000, 100);
                moveTo(x0, y0);
        }
        var xx:Number = 0;
        var yy:Number = 0;
        line.onEnterFrame = function() {
                xx = x0+i/disX;
                yy = y0-Math.sin(i*Math.PI/180)*k;
                ball._x = xx;
                ball._y = yy;
                line.lineTo(ball._x, ball._y);
                i += 5;
                if (i>disY*360) {
                        delete this.onEnterFrame;
                        ball._visible = false;
                        //
                        //==========
                        _root.createTextField("sxl001", _root.getNextHighestDepth(), 430, 380, 125, 20);
                        sxl001.background = true;
                        sxl001.backgroundColor = 0xFFCCFF;
                        sxl001.autoSize = "left";
                        sxl001.text = "===== sxl001 =====";
                        _root.createTextField("txt", _root.getNextHighestDepth(), 200, 360, 150, 20);
                        txt.text = "方向键控制曲线的移动";
                        //
                        Key.addListener(myListener);
                }
        };
}
//==  画坐标系的X轴  =========================
var v0:Number = 0;
function drawX() {
        this.createEmptyMovieClip("xline", this.getNextHighestDepth());
        with (xline) {
                lineStyle(1, 0x000000, 100);
                moveTo(20, y0);
        }
        xline.onEnterFrame = function() {
                v0 += 20;
                this.lineTo(v0, y0);
                if (this._width>=Stage.width-40) {
                        delete this.onEnterFrame;
                        v0 = 0;
                        //==  画坐标系的Y轴
                        drawY();
                }
        };
}
//==  画坐标系的Y轴  =========================
function drawY() {
        this.createEmptyMovieClip("yline", this.getNextHighestDepth());
        with (yline) {
                lineStyle(1, 0x000000, 100);
                moveTo(x0, 20);
        }
        yline.onEnterFrame = function() {
                v0 += 20;
                this.lineTo(x0, 20+v0);
                if (this._height>=Stage.height-40) {
                        delete this.onEnterFrame;
                        //显示红色小球
                        ballShow();
                }
        };
}
//== 红色小球  ====================
function ballShow() {
        this.createEmptyMovieClip("ball", this.getNextHighestDepth());
        with (ball) {
                lineStyle(6, 0xFF0000, 100);
                moveTo(0, 0);
                lineTo(0.5, 0);
                //= 画sin曲线
                drawSin();
        }
}
//==  方向键控制曲线移动 ====================
var myListener:Object = new Object();
myListener.onKeyDown = function() {
        switch (Key.getCode()) {
        case Key.LEFT :
                line._x -= 5;
                break;
        case Key.RIGHT :
                line._x += 5;
                break;
        case Key.UP :
                line._y -= 5;
                break;
        case Key.DOWN :
                line._y += 5;
                break;
        }
};
进入论坛和作者讨论学习:http://space.flash8.net/bbs/thread-345685-1-1.html
上一篇:{实例}动画实例制作:野人摇滚动画 人气:3118
下一篇:{实例}神奇的橡皮刷 人气:1337
视频教程列表
文章教程搜索
 
Flash推荐教程
Flash热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058