标题:画笔步骤录制 试题内容:做一个画笔,并记录下画笔的每一步都来,录制完后可以点击播放!其实数据存储编写方式多种多样,这里没有具体要求,通过这个练习也可以相互比较!
原文件: //录制的过程中可以停止,进行其他的重放,重放完了回到刚才录制的中断处,继续点录制可以接着录,这里我就用5秒意思一下,不然30秒太长了。 点击浏览该文件 点击浏览该文件
所有的代码如下:
import mx.controls.List; import mx.controls.Button; var inter; var draw_statue = false; var time = 0; var round = 0; var replay = false; var _obj; var This = this; var temp_arr; var temp = []; var i = 0; var hit_num; var maxtime = 5; createEmptyMovieClip("bgBoard", getNextHighestDepth()); with (bgBoard) { lineStyle(0); beginFill(0xffffff); lineTo(350, 0); lineTo(350, 300); lineTo(0, 300); endFill(); _x=30, _y=30; } createEmptyMovieClip("drawBoard", getNextHighestDepth()); function setUIObject() { createClassObject(Button, "pr_btn", getNextHighestDepth(), {label:"录制", _x:400, _y:350}); createClassObject(Button, "del_btn", getNextHighestDepth(), {label:"删除", _x:400, _y:300}); createClassObject(List, "list", getNextHighestDepth(), {_x:400, _y:30, _height:250}); createTextField("statue", getNextHighestDepth(), 300, 350, 100, 20); createTextField("myname", getNextHighestDepth(), 10, 350, 100, 20); myname.text = "寒冰制造"; statue.text = "等待中。。。"; pr_btn.onPress = function() { (!replay) ? ((this.label == "录制") ? (draw_statue=true, this.label="停止", statue.text="录制中。。。", timeRun(this)) : (clearInterval(_obj.mc.inter), clearInterval(inter), draw_statue=false, this.label="录制", statue.text="等待中。。。")) : null; }; _obj = {}; _obj.mc = createEmptyMovieClip("r_run", getNextHighestDepth()); _obj.change = function(eventObj) { hit_num = eventObj.target.selectedIndex; clearInterval(inter); statue.text = "重放中。。。"; pr_btn.label = "录制"; replay = true; var This = this.mc; This.clear(); This.lineStyle(0, 0xff0000); This.i = 0; temp_arr = eventObj.target.value; drawBoard.clear(); This.moveTo(temp_arr[0].x, temp_arr[0].y); clearInterval(This.inter); This.inter = setInterval(function () { if (++This.i if (temp_arr[This.i].d == "p") { This.moveTo(temp_arr[This.i].x, temp_arr[This.i].y); } This.lineTo(temp_arr[This.i].x, temp_arr[This.i].y); statue.text = "重放中。。。"; pr_btn.label == "录制"; } else { clearInterval(This.inter); replay = false; This.clear(); if (temp.length>0) { drawBoard.lineStyle(0, 0xff0000); drawBoard.moveTo(temp[0].x, temp[0].y); for (var j = 1; j if (temp[j].d == "p") { drawBoard.moveTo(temp[j].x, temp[j].y); } drawBoard.lineTo(temp[j].x, temp[j].y); } } statue.text = "等待中。。。"; pr_btn.label == "录制"; draw_statue=false;//加上了这个,应该就没问题了,变量太多容易遗漏。。 // timeRun(pr_btn); } }, 10); }; list.addEventListener("change", _obj); del_btn.onPress = function() { list.removeItemAt(hit_num); _obj.mc.clear(); clearInterval(_obj.mc.inter); replay = false; statue.text = "等待中。。。"; pr_btn.label == "录制"; }; } function timeRun(u) { inter = setInterval(function () { time++; statue.text = "录制中。。。"+time+"秒"; if (time>=maxtime) { time = 0; round++; list.addItem({label:"第"+round+"次", data:temp}); u.label = "录制"; statue.text = "等待中。。。"; draw_statue = false; drawBoard.clear(); temp = []; onMouseMove = null; clearInterval(inter); } }, 1000); } bgBoard.useHandCursor = false; bgBoard.onPress = function() { if (draw_statue) { temp.push({x:_xmouse, y:_ymouse, d:"p"}); press = true; drawBoard.lineStyle(0, 0xff0000); drawBoard.moveTo(_xmouse, _ymouse); } onMouseMove = function () { if (press and bgBoard.hitTest(_xmouse, _ymouse)) { temp.push({x:_xmouse, y:_ymouse}); drawBoard.lineTo(_xmouse, _ymouse); } }; }; onMouseUp = function () { onMouseMove = null; press = false; }; setUIObject(); |
|