经典hbro写的FLASH绘图回放功能

      flash As 2007-2-5 18:46:00
HBrO

超级版主



帖子 4697
体力 12653
威望 209
注册 2004-12-1    #10
发表于 2005-4-16 19:21  资料 主页 短消息   
源文件我已经做好了,是一个简单的画直线的画板.做法如下:
新建两个按钮,实例名分别为undo,redo
然后,在帧里输入如下代码:
var lines = new XML("<?xml version=\"1.0\" standalone=\"no\"?><lines></lines>");
var num = 0;
function DrawLine(id, depth, x1, y1, x2, y2) {
       this.createEmptyMovieClip(id, depth);
       with (this[id]) {
              lineStyle(1, 0x000000, 100);
              moveTo(x1, y1);
              lineTo(x2, y2);
       }
}
this.onMouseDown = function() {
       dragging = true;
       startpointx = _xmouse;
       startpointy = _ymouse;
       moved = false;
};
this.onMouseUp = function() {
       dragging = false;
       if (moved) {
              tempnode = new XML("<line x1=\""+startpointx+"\" x2=\""+_xmouse+"\" y1=\""+startpointy+"\" y2=\""+_ymouse+"\"></line>");
              lines.childNodes[0].appendChild(tempnode);
              trace(lines.toString());
              lines = new XML(lines.toString());
              num += 1;
              moved = false;
       }
       moved = false;
};
this.onMouseMove = function() {
       moved = true;
       if (dragging) {
              DrawLine("line"+num, num, startpointx, startpointy, _xmouse, _ymouse);
       }
       updateAfterEvent(this.onMouseMove);
};
undo.onPress=function(){
       dragging=false;
}
redo.onPress=undo.onPress
undo.onRelease = function() {
       moved = false;
       num--;
       removeMovieClip("line"+num);
};
redo.onRelease = function() {
       moved = false;
       startpointx = lines.childNodes[0].childNodes[num].attributes.x1;
       startpointy = lines.childNodes[0].childNodes[num].attributes.y1;
       endpointx = lines.childNodes[0].childNodes[num].attributes.x2;
       endpointy = lines.childNodes[0].childNodes[num].attributes.y2;
       DrawLine("line"+num, num, startpointx, startpointy, endpointx, endpointy);
       num++;
};
功能还不完善,不过希望你从中能有所启发.
标签集:TAGS:
回复Comments() 点击Count()
喜欢就顶一下

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}