Flash中背景跟随时间变化

跟随

  如果flash中,我们想实现一张图片随着计算机时间的变换,图片也发生变化,形成早晨,晚上等效果。(如果多个图片,也能用这个方法实现,下面,我们看一下案例):

    相对应的脚本: function times() 

    hh = new Date(); 
    xiaoshi = hh.getHours(); 
    mm = new Date(); 
    fengzhong = mm.getMinutes(); 
    nowtime = xiaoshi * 60 + fengzhong; 
    if (nowtime >= 0 && nowtime <= 300 || nowtime > 1200 && nowtime < 1440) 
    { 
        skycolor = [5, 18, 7, -14, 29, -10, 100, 0]; 
    } // end if 
    if (nowtime > 300 && nowtime <= 330) 
    { 
        skycolor = [5 + (nowtime - 300) * 1.500000, 18 - (nowtime - 300) * 2.930000, 7 + (nowtime - 300) * 1.200000, -14 - (nowtime - 300) * 1.230000, 29 + (nowtime - 300), -10 - (nowtime - 300) * 1.330000, 100, 0]; 
    } // end if 
    if (nowtime > 330 && nowtime <= 350) 
    { 
        skycolor = [49 + (nowtime - 330) * 1.050000, -70, 43 + (nowtime - 330) * 1.100000, -51, 58 + (nowtime - 330) * 0.600000, -50, 100, 0]; 
  
    } // end if 
    if (nowtime > 350 && nowtime <= 360) 
    { 
        skycolor = [70 - (nowtime - 350) * 2.100000, -70 + (nowtime - 350) * 12.100000, 65 + (nowtime - 350) * 0.700000, -51 + (nowtime - 350) * 1.800000, 70 - (nowtime - 350) * 1.400000, -50 + (nowtime - 350) * 5, 100, 0]; 
    } // end if 
    if (nowtime > 360 && nowtime <= 375) 
    { 
        skycolor = [49 + (nowtime - 361) * 0.357100, 51 + (nowtime - 361) * 3.071000, 72 - (nowtime - 361) * 1.285700, -33 + (nowtime - 361) * 5.710000, 56, 0 + (nowtime - 361) * 5, 100, 0]; 
    } // end if 
    if (nowtime > 375 && nowtime <= 390) 
    { 
        skycolor = [54 + (nowtime - 375) * 3.067000, 94 - (nowtime - 375) * 5.875000, 54 + (nowtime - 375) * 3.067000, 47 - (nowtime - 375) * 3.133000, 54 + (nowtime - 375) * 3.067000, 70 - (nowtime - 375) * 4.667000, 100, 0]; 
    } // end if 
    if (nowtime > 390 && nowtime <= 870) 
    { 
        skycolor = [100, (nowtime - 390) * 0.062500, 100, (nowtime - 390) * 0.062500, 100, (nowtime - 390) * 0.062500, 100, 0]; 
    } // end if 
    if (nowtime > 870 && nowtime <= 990) 
    { 
        skycolor = [100, 30 - (nowtime - 870) * 0.250000, 100, 30 - (nowtime - 870) * 0.250000, 100, 30 - (nowtime - 870) * 0.250000, 100, 0]; 
    } // end if 
    if (nowtime > 990 && nowtime <= 1050) 
    { 
        skycolor = [100 - (nowtime - 990) * 0.167000, (nowtime - 990) * 0.767000, 100 - (nowtime - 990) * 0.167000, 0, 100 - (nowtime - 990) * 0.167000, 0, 100, 0]; 
    } // end if 
    if (nowtime > 1050 && nowtime <= 1070) 
    { 
        skycolor = [90 + (nowtime - 1050) * 0.500000, 46 + (nowtime - 1050) * 6.250000, 90 + (nowtime - 1050) * 0.500000, -(nowtime - 1050) * 0.250000, 90 - (nowtime - 1050) * 0.800000, -(nowtime - 1050) * 2.100000, 100, 0]; 
    } // end if 
    if (nowtime > 1070 && nowtime <= 1080) 
    { 
        skycolor = [100 - (nowtime - 1070) * 1.700000, 171 - (nowtime - 1070) * 6, 100 - (nowtime - 1070) * 1.700000, -5, 74 - (nowtime - 1070) * 0.900000, -42 + (nowtime - 1070) * 5.500000, 100, 0]; 
    } // end if 
    if (nowtime > 1080 && nowtime <= 1110) 
    { 
        skycolor = [83 - (nowtime - 1080) * 0.433000, 111 - (nowtime - 1080) * 5.100000, 83 - (nowtime - 1080) * 0.433000, -5 - (nowtime - 1080) * 1.233000, 65 + (nowtime - 1080) * 0.366700, 13 - (nowtime - 1080) * 2, 100, 0]; 
    } // end if 
    if (nowtime > 1110 && nowtime <= 1200) 
    { 
        skycolor = [70 - (nowtime - 1110) * 0.722000, -42 + (nowtime - 1110) * 0.667000, 70 - (nowtime - 1110) * 0.700000, -42 + (nowtime - 1110) * 0.310000, 76 - (nowtime - 1110) * 0.522000, -47 + (nowtime - 1110) * 0.411000, 100, 0]; 
    } // end if 
    sk = new Color(sky); 
    x1 = {ra: skycolor[0], rb: skycolor[1], ga: skycolor[2], gb: skycolor[3], ba: skycolor[4], bb: skycolor[5], aa: skycolor[6], ab: skycolor[7]}; 
    sk.setTransform(x1); 
    m1 = new Color(mc1); 
    x2 = {ra: m1color[0], rb: m1color[1], ga: m1color[2], gb: m1color[3], ba: m1color[4], bb: m1color[5], aa: m1color[6], ab: m1color[7]}; 
    m1.setTransform(x2); 
    m2 = new Color(mc2); 
    x3 = {ra: m2color[0], rb: m2color[1], ga: m2color[2], gb: m2color[3], ba: m2color[4], bb: m2color[5], aa: m2color[6], ab: m2color[7]}; 
    m2.setTransform(x3); 
    m3 = new Color(mc3); 
    x4 = {ra: m3color[0], rb: m3color[1], ga: m3color[2], gb: m3color[3], ba: m3color[4], bb: m3color[5], aa: m3color[6], ab: m3color[7]}; 
    m3.setTransform(x4); 
    m4 = new Color(mc4); 
    x5 = {ra: m4color[0], rb: m4color[1], ga: m4color[2], gb: m4color[3], ba: m4color[4], bb: m4color[5], aa: m4color[6], ab: m4color[7]}; 
    m4.setTransform(x5); 
    d = new Color(dao); 
    x6 = {ra: dcolor[0], rb: dcolor[1], ga: dcolor[2], gb: dcolor[3], ba: dcolor[4], bb: dcolor[5], aa: dcolor[6], ab: dcolor[7]}; 
    d.setTransform(x6); 
    y1 = new Color(yun1); 
    y2 = new Color(yun2); 
    y3 = new Color(yun3); 
    sun = new Color(mc5); 
    x7 = {ra: yuncolor[0], rb: yuncolor[1], ga: yuncolor[2], gb: yuncolor[3], ba: yuncolor[4], bb: yuncolor[5], aa: yuncolor[6], ab: yuncolor[7]}; 
    y1.setTransform(x7); 
    y2.setTransform(x7); 
    y3.setTransform(x7); 
    sun = new Color(mc5); 
    sun.setTransform(x4); 
    sky2 = new Color(_root.home.all.sky2); 
    sky2.setTransform(x1); 
} // End of the function 
function suntimes() 

    if (nowtime >= 540 && nowtime <= 900) 
    { 
        mc5._y = -45; 
        if (nowtime <= 720) 
        { 
            mc5._rotation = 180 + (nowtime - 540) * 0.388000; 
        } // end if 
        if (nowtime > 720) 
        { 
            mc5._rotation = 250 + (nowtime - 720) * 0.611000; 
        } // end if 
    } 
    else 
    { 
        if (nowtime < 540 && nowtime >= 360) 
        { 
            mc5._y = 180 - (nowtime - 360) * 1.250000; 
            mc5._rotation = 180; 
        } // end if 
        if (nowtime >= 900 && nowtime <= 1110) 
        { 
            mc5._y = -45 + (nowtime - 900) * 0.900000; 
            mc5._rotation = 0; 
        } // end if 
        if (nowtime >= 0 && nowtime < 360 || nowtime > 1100 && nowtime <= 1440) 
        { 
            mc5._alpha = 0; 
        } 
        else 
        { 
            mc5._alpha = 100; 
        } // end if 
    } // end if 
    if (nowtime > 360 && nowtime <= 720) 
    { 
        mc5.sun._xscale = 130 - (nowtime - 360) * 0.166700; 
        mc5.sun._yscale = mc5.sun._xscale; 
    } 
    else if (nowtime > 720 && nowtime <= 1080) 
    { 
        mc5.sun._xscale = 70 + (nowtime - 720) * 0.166700; 
        mc5.sun._yscale = mc5.sun._xscale; 
    } // end if 
} // End of the function 
function moontimes() 

    if (nowtime >= 1260 && nowtime < 1440 || nowtime >= 0 && nowtime < 180) 
    { 
        moon._y = -45; 
        if (nowtime < 1440) 
        { 
            moon._rotation = 180 + (nowtime - 1260) * 0.388900; 
        } // end if 
        if (nowtime >= 0 && nowtime < 180) 
        { 
            moon._rotation = 250 + nowtime * 0.611000; 
        } // end if 
    } 
    else 
    { 
        if (nowtime < 1260 && nowtime > 1080) 
        { 
            moon._y = 75 - (nowtime - 1080) * 0.666700; 
            moon._rotation = 180; 
        } // end if 
        if (nowtime > 180 && nowtime < 1080) 
        { 
            moon._y = -45 + (nowtime - 180) * 0.666700; 
            moon._rotation = 0; 
        } // end if 
    } // end if 
    if (nowtime >= 1080 && nowtime <= 1260) 
    { 
        moon._alpha = Math.round((nowtime - 1080) * 0.555600); 
        star._alpha = Math.round((nowtime - 1080) * 0.555600); 
    } // end if 
    if (nowtime > 1260 && nowtime < 1440 || nowtime > 0 && nowtime < 240) 
    { 
        moon._alpha = 100; 
        star._alpha = 100; 
    } // end if 
    if (nowtime >= 240 && nowtime <= 360) 
    { 
        moon._alpha = 100 - Math.round((nowtime - 240) * 0.833300); 
        star._alpha = 100 - Math.round((nowtime - 240) * 0.833300); 
    } // end if 
    if (nowtime > 360 && nowtime < 1080) 
    { 
        moon._alpha = 0; 
        star._alpha = 0; 
    } // end if 
    if (nowtime > 1080 && nowtime < 1440) 
    { 
        moon.moons._xscale = 130 - (nowtime - 1080) * 0.138890; 
        moon.moons._yscale = moon.moons._xscale; 
    } 
    else if (nowtime > 0 && nowtime <= 360) 
    { 
        moon.moons._xscale = 80 + nowtime * 0.138890; 
        moon.moons._yscale = moon.moons._xscale; 
    } // end if 
} // End of the function 
var hh; 
var xiaoshi; 
var mm; 
var ss; 
var fengzhong; 
var nowtime; 
MovieClip.prototype.moveIn = function () 

    var _l1 = this; 
    _l1.onEnterFrame = function () 
    { 
        var _l1 = this; 
        if (_l1._currentframe < _l1._totalframes) 
        { 
            _l1.nextFrame(); 
        } 
        else 
        { 
            delete _l1["onEnterFrame"]; 
        } // end if 
    }; 
}; 
MovieClip.prototype.moveOut = function () 

    var _l1 = this; 
    _l1.gotoAndStop(_l1._totalframes); 
    _l1.onEnterFrame = function () 
    { 
        var _l1 = this; 
        if (_l1._currentframe > 1) 
        { 
            _l1.prevFrame(); 
        } 
        else 
        { 
            delete _l1["onEnterFrame"]; 
        } // end if 
    }; 
}; 
onEnterFrame = function () 

    ss = new Date(); 
    miao = ss.getSeconds(); 
    if (miao == 59) 
    { 
        times(); 
        suntimes(); 
        moontimes(); 
    } // end if 
};
  特别说明:这个代码最下面不是用来控制背景变化的,而是用来控制到了晚上月亮出现的位置,星星的位置。白天这些画面消失的控制。由于时间缘故。本人没有将这些画面放上了。如果大家感兴趣的话。我后面会完成的。

时间: 2024-08-03 07:46:16

Flash中背景跟随时间变化的相关文章

Flash中变色背景的实现技巧

技巧 效果简介: 本例巧妙地运用Flash中颜色对象.帧与标签的跳转技巧以及函数的创建方法.本例的效果演示也很有意思:只要轻轻滑一下鼠标,动画的背景就变了色:如果跳转到变色背景的点击模式下,就可以点击鼠标改变背景的颜色了.好了,下面就让我们动手设计吧. 演示效果: 点击这里下载源文件 1.打开打开Flash MX 2004,如图1所示新建一个Flash文档.按快捷键Ctrl+F3打开"属性"面板,如图2所示单击"文档属性"按钮打开"文档属性"面板

Flash跟随鼠标变化的滤镜效果

跟随|跟随鼠标|滤镜 本实例使用flash8制作和发布,请把你的ie浏览插件更新为flash8查看- 点击这里下载源文件 制作主要使用如下方法: 1.制作一个MC,拖入到舞台上,修改实例名为myMC 2.添加下列代码: import flash.filters.*;//载入滤镜类 // 定义初始斜角滤镜的偏移距离 var maxbeveldistance:Number = 5; // 创建一个斜角滤镜 var bevel:BevelFilter = new BevelFilter(); // 定

Flash中俯视视角的动画背景

俯视视角是指镜头从上向下观察的状态.由于俯视效果在视觉上给欣赏者的震撼性最大,所以很多作品都采用这项技法. 1. 运行flash mx,文档属性默认. 2. 设置视平线.余点和地点.地点是指物体向下消失的点.如图23所示. 3. 在视平线以下.两个余点之间绘制一条垂直线段. 4. 垂直线段的两个端点分别于两个余点连接,并连接地点.如图24所示. 5. 利用平行视角绘制门窗的方法,就可以完成这幅俯视效果透视图了.如图25所示.效果完成. 以上向大家介绍了三种基本的视角绘制方法.这三种透视效果都属于

轻松实现Flash动态背景

动态 今天我们为大家介绍几种Flash中常用动态背景的简单制作方法,主要运用随机数,步骤简单,但效果非常不错. 一.晃动的竖线 原文件下载学习 这个效果非常常用,其实实现起来也比较简单,主要通过控制MC的x坐标来实现. 新建一个MC,命名为line_g,画一条竖线,坐标(0,0). 注意:在这种需要控制坐标的flash中每个MC的初始坐标值都是很重要的,否则你很难弄清楚那个该死的MC到底跑到哪去了,即使是普通的flash,我们也最好制作得规范一些,这样看上去很清晰,检查起来也很方便. 再新建一个

Flash中的物理运动动画编程

编程 本文译者:egoldy 文章出处: http://www.bit-101.com 文章性质:翻译 译者网站很值得一看:http://www.webstudio.com.cn/ Actionscript animation 简明教程 本教程节选自bit-101.com的未正式出版的新书making things move的新书介绍.主要内容是关于速度,加速度,弹性,缓动,摩擦力,重力等内容,这里没有非常详尽的内容,如果你想知道更详尽的内容,可以预定购买作者的新书making things m

flash实时音乐真实频率变化(全as)正在直播教程

效果显示:http://k.thec.cn/liuping2006/music_jump_line/music_jump_line.swf 如果感大家兴趣,我将介绍制作方法. 实时音频跳动条的制作 Flash对声音的处理主要有: 就目前Flash的已有版本(Flash5.FlashMX.Flash2004.Flash8),Flash对声音文件的处理能力还是不够强大的. mp3是目前网络上最为大众的声音格式,原因是mp3有高效率的压缩(约1/12),并能很好地保持原有声音的音质. Flash有两种

Flash中的电影艺术之镜头技巧教程

技巧|教程 文章内容摘自<Flash动画与卡通制作创意导航>([美]Ibis Fernanadez著 罗小燕译 清华大学出版社) ,有改动,实例作品为若无说明为qhwa原创. 对于许多动画制作者来说,通过Flash获得电影般的效果十分困难,这样他们就不得不满足于非常规的处理方法或者静态画面,而这样又影响了他们的制作.只会说话的头十分枯燥,而且有时仅仅画出角色正确的动作和姿态是远远不够的. 电影艺术融化了摄影,舞蹈动作设计和影视编辑技术,其中影视编辑技术对于成功制作卡通动画来说起主导作用.通常,

Flash中实现物体运动的三种方法

现在用Flash开发的游戏是越来越多了.很多朋友也很想学习用Flash制作游戏的方法.大家知道,不管在什么游戏中,实现物体的运动是游戏的前提,而不同的游戏里物体移动的方式又不尽相同.所以,想学习制作Flash游戏的朋友今天就先随我一起学学在Flash中实现物体运动的几种方法吧.几种方法如下: 方法一:通过单击按钮实现物体的单位运动 这种方法一般在需要按键的游戏中使用.你也可以给某个实体加上这段代码,然后通过单击这个实体达到某种游戏效果. 1.打开Flash,按快捷键"Ctrl + M"

Flash 中的文字绕排效果

我们见过许多文字绕排的效果,使用得当,会给作品增色不少,而且现在可以做这个效果的工具也非常多,例如 CorelDraw ; FreeHand 等,把这应用进 Flash 该如何做呢?通常我们都是使用外部绘画工具如 FreeHand 做好绕排效果,然后输出标准的 *.AI 格式文件,然后再导入 Flash 来实现目的.那如果我们没有这样的第三方工具怎么办?可以独立在 Flash 中做出这个效果吗?答案是肯定的,虽然现在 Macromedia 已经将最新的 FreeHand 9 和 Flash 4