Flash:相片浏览器 V1.0 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

    浏览器

将相片与flash放在同一目录下,相片命名为0.jpg,1.jpg,2.jpg,3.jpg,4.jpg,5.jpg....以至无穷(0.jpg为相册的封面),

Flash:相片浏览器 V1.0

。然后打开FLASH就可以看到效果了。

    注意:用flash8播放器才能正常观看

    相册test.rar

    源文件.rar

    源文件主轴代码:

    帧1: 主要是把舞台限定,全屏

    帧2: 加载封面图片,当按下左键就用个ENTERFRAME事件来隐去封面,并在动作完成后到下一帧,也就是舞台正常主状态

    帧3: 回载缩略图,初始化一些变量

    帧4: 主体帧。初始化完成,则在这一帧STOP,大多数时候舞台画面都是在这一帧显示

    帧5: 动作过渡帧。如果要加载下几张图,就跳到帧3,把缩略图重加载一遍,再在帧4停止,呼应鼠标事件

    帧1:

    fscommand("fullscreen", true);//全屏

    stop();

    //初始化画图状态,并画屏幕大小的一个矩形,用它把舞台遮照,这样露在舞台外面的部分就看不到了,使画面更完美一些。

    clear(); //初始化

    //画矩形

    createEmptyMovieClip("line0", 999);

    with(line0){

    lineStyle(1, 0x66FFFF, 100);

    beginFill(0xFF6600, 100);

    moveTo(0,0);

    lineTo(Stage.width,0);

    lineTo(Stage.width,Stage.height);

    lineTo(0,Stage.height);

    endFill(); }

    //用矩形遮照舞台

    _root.setMask(_root.line0);

    //鼠标按下继续下一画面

    _root.onMouseDown = function() {

    play();}

帧2:

    stop();

    var pic_count:Number = 0;//此变量用来计录当前显示图片缩略图的计数,是显示1,2,3,4,5张,还是6,7,8,9,10张,还是。。。

    //----------为所有影片夹子设置变色方法,它需和onEnterFrame配合使用

    MovieClip.prototype.setBrightOffset = function(offset) {

    var This = new Color(this);

    var trans = This.getTransform();

    with (trans) {

    rb = gb=bb=offset;

    }

    This.setTransform(trans);

    };

    //封面的图片显示,也就是第二个画面,调用“theloader”来显示,后面的缩略图也是用这一影片夹子来加载的

    _root.attachMovie("theloader", "theloader0", 1);

    theloader0.canplay = true;//图片加载完毕后不作就位动作,由此值作统一指挥(后面缩略图就是用这值来控制一张张出来的)

    _root.theloader0.num = 0;//加载第几张图的控制变量,这时加载封面,也就是"0.jpg"

    _root.theloader0.howwide = Stage.height+10;//显示的图片的高度限制

    _root.theloader0._x = 0;

    _root.theloader0._y = 0;

    //图片加载后就自己作渐隐动作,由EnterFrame事件加影片夹子的变色属性来实现,等于255值时图片呈白色,并实施跳转到下一画面

    j = 1;

    _root.onEnterFrame = function() {

    if (j<255) {

    _root.theloader0._x = (Stage.width-_root.theloader0.loadit_mc._width)/2;//将图片在屏幕中间显示

    _root.theloader0._y = (Stage.height-_root.theloader0.loadit_mc._height)/2;//将图片在屏幕中间显示

    _root.theloader0.setBrightOffset(j);

    j += j/6;//作显示加速效果,渐渐加快

    } else {//删除变色动作,到下一画面

    delete _root.onEnterFrame;

    play();

    }

    };

帧3:

    removeMovieClip("theloader0");//删除上一画面

帧4:

    stop();

    var howmany_x:Number = 5;//缩略图一次显示5张

    var top_position:Number = 20;//缩略图的坐标值高低控制

    for (i=0; i

    _root.attachMovie("theloader", "theloader"+i, 100*i);//加载

    _root["theloader"+i].num = pic_count+i+1;//告诉每一个缩略图夹子应加载第几张JPG

    _root["theloader"+i].howwide = 65;//控制图片的高度值(x,y的scale值是统一设定的,对高度设定就等于限定了宽度)

    _root["theloader"+i]._x = top_position+Stage.width/howmany_x*i*1.35-10*i*i;//缩略图x坐标位置

    //trace(_root["theloader"+i]._x);

    _root["theloader"+i]._y = 20*Math.sin(360+0.3*i);//让缩略图的Y值呈曲线分布

    _root["theloader"+i]._xscale = _root["theloader"+i]._yscale=110-100/howmany_x*i;//越靠后的缩略图越小张

    _root["theloader"+i]._rotation = i*7;//对每个缩略图增加一点旋转

    }

    _root.onMouseDown = function() {//舞台上鼠标按下响应,如果鼠标是点在缩略图上就执行舞台主图替换操作

    for (i=0; i

    if (_root["theloader"+i].hitTest(_root._xmouse, _root._ymouse)) {

    _root.getit.num = pic_count+i+1;//得此时缩略图对应的图片序号

    //trace(_root.getit.thenum);

    _root.getit.gotoAndPlay(2);//"getit"重新加载图片

    break;//同一时刻只有一个缩略图被点击,所以只要侦测到有缩略图被点击就退出FOR循环

    }

    }

    };

    //让缩略图逐一出来的时间函数,只有CANPLAY被置为true时,才执行每个缩略图动作,

电脑资料

Flash:相片浏览器 V1.0》(https://www.unjs.com)。缩略图动作执行会检查这个值。

    k = -1;

    var countit = setInterval(function () {

    if (k

    k++;

    _root["theloader"+k].canplay = true;//每隔100毫秒就把下一张缩略图动作启动

    } else {

    clearInterval(countit);//缩略图加载完就删除定时函数

    }

    }, 100);

帧5:

    gotoAndPlay("reload");//如果舞台上的换下面五张图的按钮(最大的那个按钮)被点击,就重新下载下五张缩略图,边上的小按钮点击则加载前五张图

另外附上:

    主体大图的互动响应事件说明:

    分为左键按下,松开两大事件。

    ("getit"时间主轴上的函数,以下"this"指的是大图这个影片夹子):

    //鼠标左键按下

    this.onMouseDown = function() {//如果鼠标在大图上按下,记录其位置坐标,大图此时激活拖动功能

    if (this.hitTest(_root._xmouse, _root._ymouse)) {

    the_xmouse1 = _root._xmouse;//记录X值

    the_ymouse1 = _root._ymouse;//记录Y值

    this.startDrag(lock);//能够拖动,这里不加判断了,只要按下就拖动。因为反正如果是双击动作的话,拖动距离也不会大的。

    }

    };

    //鼠标左键松开

    this.onMouseUp = function(a) {

    this.stopDrag();//停止拖动

    if (this.hitTest(_root._xmouse, _root._ymouse)) {

    the_xmouse2 = _root._xmouse;//记录停下后的X值

    the_ymouse2 = _root._ymouse;//记录停下后的Y值

    the_x = this._x;//记住当前大图的坐标

    the_y = this._y;//记住当前大图的坐标

    count = Math.sqrt(the_xmouse1-the_xmouse2)+Math.sqrt(the_ymouse1-the_ymouse2);//用两点距离公式计算鼠标按下到松开过程中移动的距离

    //------------

    doubleclick = false;//初始化双击的监控变量值

    //用系统自带gettime函数来检测两个鼠标按下动作的间隔,如果时间极快(小于400毫秒)就认为当前做了双击左键动作

    var currentTime:Number = new Date().getTime();

    // 用一个

    if (_global.lastTime == undefined) {//上一次左键按下的时间,没有就记录这一次按下的时间

    // 初始化 _global.lastTime

    _global.lastTime = currentTime;

    } else if (currentTime-_global.lastTime<400) {//拿此次的时间和上次的按下时间作比较,小于400ms就将双击的监控变量改为true

    doubleclick = true;

    }

    _global.lastTime = currentTime;//lasttime作为全局变量,所以值不会随函数执行完而消失,每次函数执行就更新一次

    //如果双击事件确认,并且两次动作的距离值小于4(说明不是想拖动大图,否则拖动的距离一般会比4大),就执行双击响应

    if (_root.hitbut != true && count<4) {//如果这个动作不是发生在按缩略图的动作上(而是按在大图上),而且距离是双击的距离就条件成立

    if (doubleclick == true) {//时间上也比较合理的话,那就是双击,错不了了,呵~

    loadit_mc._xscale = loadit_mc._yscale=this.a;//回复刚加载时的大小

    this._x = (Stage.width-loadit_mc._width)/2;//复位,放在下边空白处的中间

    this._y = (Stage.height-loadit_mc._height)/2;//复位,放在下边空白处的中间

    redrawit();//用画边函数加上图片的边框

    } else {//在上面的判断下,如果不是双击(比双击时间长),就一定是单击了,那就执行放大动作,每次大10个百分点,别忘了放大后的位置修正

    loadit_mc._xscale += 10;

    loadit_mc._yscale += 10;

    this._x = this._x-Math.abs(the_x-the_xmouse2)*.109;

    this._y = this._y-Math.abs(the_y-the_ymouse2)*.109;

    redrawit();

    }

    } else {

    _root.hitbut = false;//以上都不是的话就不管了,把该复位的值复下位

    }

    }

    };

希望对代码初学者能有帮助。

最新文章