// variables
drawing=false;
fill=false;
snapTo=false;
ncolor='0x000000';
shapedata=new Array();
shapes=new Array();
shapecount=0;
// keypress listeners for keyboard shortcuts
createEmptyMovieClip('_keyListener',1000);
Key.addListener(_keyListener);
_keyListener.onKeyDown=function(){
switch(Key.getCode()){
case 49 : _root.linethickness.text=1;break;
case 97 : _root.linethickness.text=1;break;
case 50 : _root.linethickness.text=2;break;
case 98 : _root.linethickness.text=2;break;
case 51 : _root.linethickness.text=3;break;
case 99 : _root.linethickness.text=3;break;
case 52 : _root.linethickness.text=4;break;
case 100 : _root.linethickness.text=4;break;
case 53 : _root.linethickness.text=5;break;
case 101 : _root.linethickness.text=5;break;
case 54 : _root.linethickness.text=6;break;
case 102 : _root.linethickness.text=6;break;
case 55 : _root.linethickness.text=7;break;
case 103 : _root.linethickness.text=7;break;
case 56 : _root.linethickness.text=8;break;
case 104 : _root.linethickness.text=8;break;
case 57 : _root.linethickness.text=9;break;
case 105 : _root.linethickness.text=9;break;
case 76 : _root.shape.text='line';_root.highlighter._x=200;break;
case 67 : _root.shape.text='curve';_root.highlighter._x=300;break;
case 82 : _root.shape.text='rectangle';_root.highlighter._x=400;break;
case 79 : _root.shape.text='circle';_root.highlighter._x=500;break;
case 80 : _root.shape.text='pen';_root.highlighter._x=100;if(drawing){moveTo(_xmouse,_ymouse);_root.tracker.clear();}break;
case 83 : if(snapTo){snapTo=false;}else{snapTo=true;}break;
case 70 : if(fill){_root.fillstatus.text='Fill '+fill=false;}else{_root.fillstatus.text='Fill '+fill=true;}break;
case 88 : for(sc=0;sc<_root.shapes.length;sc++){removeMovieClip(shapes[sc]);}_root.shapes=new Array();_root.shapedata=new Array();if(drawing && shape=='pen'){moveTo(_xmouse,_ymouse);}drawing=false;_root.tracker.clear();break;
case 90 : if(shapecount>0){removeMovieClip(shapes[shapecount]);shapes[shapecount]='';shapedata[shapecount]='';shapecount--;}break;
}
// set the rgb color picker's scale based on linethickness
_root.cp._y=330-_root.linethickness.text/2;
_root.cp._height=_root.linethickness.text;
_root.cp._yscale=Math.floor(_root.cp._yscale);
};
// end key listener
// draw curves
function curve(it,startX,startY,mouseX,mouseY){
with(eval(it)){moveTo(startX,startY);curveTo(mouseX,startY,mouseX,mouseY);}
}
// draw ovals/circles
function circle(it,x,y,mouseX,mouseY){
if(Key.isDown(Key.SHIFT)){
a=b=Math.sqrt(Math.pow(Math.abs(mouseX-x),2)+Math.pow(Math.abs(mouseY-y),2));
}else{
a=Math.abs(mouseX-x);
b=Math.abs(mouseY-y);
}
j=a*0.70711;
n=b*0.70711;
i=j-(b-n)*a/b;
m=n-(a-j)*b/a;
with(eval(it)){
if(fill){beginFill(_root.ncolor,100);}
moveTo(x+a,y);
curveTo(x+a,y-m,x+j,y-n);
curveTo(x+i,y-b,x,y-b);
curveTo(x-i,y-b,x-j,y-n);
curveTo(x-a,y-m,x-a,y);
curveTo(x-a,y+m,x-j,y+n);
curveTo(x-i,y+b,x,y+b);
curveTo(x+i,y+b,x+j,y+n);
curveTo(x+a,y+m,x+a,y);
if(fill){endFill();}
}
}
// draw rectangles
function rectangle(it,startX,startY,mouseX,mouseY){
with(eval(it)){
if(fill){beginFill(_root.ncolor,100);}
lineTo(mouseX,startY);
lineTo(mouseX,mouseY);
lineTo(startX,mouseY);
lineTo(startX,startY);
if(fill){endFill();}
}
}
// root event handlers
with(_root){
onMouseDown=function(){
// check if mouse is on canvas
// and begin drawing if so
if(_root._ymouse<300 && _root.cp.hitTest(_root._xmouse,_root._ymouse,false)==false){
drawing=true;
startX=snapTo?Math.ceil(_xmouse/10)*10:_xmouse;
startY=snapTo?Math.ceil(_ymouse/10)*10:_ymouse;
if(_root.shape.text=='pen'){
// if current shape is pen, create new MC
penX=_xmouse;
penY=_ymouse;
shapecount++;
shapes[shapecount]='SMC_'+shapecount;
_root.createEmptyMovieClip(shapes[shapecount],1000+shapecount);
with(eval(shapes[shapecount])){moveTo(penX,penY);}
}
}
};
onMouseUp=function(){
// check if mouse is still on the canvas
if(_root.canvas.hitTest(_root._xmouse,_root._ymouse,false)){
if(drawing){
drawing=false;
// clear the tracking clip and create the new shape
tracker.clear();
shapecount++;
shapes[shapecount]='SMC_'+shapecount;
_root.createEmptyMovieClip(shapes[shapecount],shapecount+1000);
thickness=_root.linethickness.text;
with(eval(shapes[shapecount])){
lineStyle(thickness,_root.ncolor);
moveTo(startX,startY);
}
endX=snapTo?Math.floor(_xmouse/10)*10:_xmouse;
endY=snapTo?Math.floor(_ymouse/10)*10:_ymouse;
if(_root.shape.text=='line'){shapedata[shapecount]='line_'+startX+'_'+startY+'_'+endX+'_'+endY+'_'+thickness+'_'+_root.ncolor+'_false-';with(eval(shapes[shapecount])){lineTo(endX,endY);}}
if(_root.shape.text=='curve'){shapedata[shapecount]='curve_'+startX+'_'+startY+'_'+endX+'_'+endY+'_'+thickness+'_'+_root.ncolor+'_false-';curve(shapes[shapecount],startX,startY,endX,endY);}
if(_root.shape.text=='rectangle'){shapedata[shapecount]='rectangle_'+startX+'_'+startY+'_'+endX+'_'+endY+'_'+thickness+'_'+_root.ncolor+'_'+fill+'-';rectangle(shapes[shapecount],startX,startY,endX,endY);}
if(_root.shape.text=='circle'){
if(Key.isDown(Key.SHIFT)){
r=Math.sqrt(Math.pow(Math.abs(startX-endX),2)+Math.pow(Math.abs(startY-endY),2));
shapedata[shapecount]='circle_'+startX+'_'+startY+'_'+(startX+r)+'_'+(startY+r)+'_'+thickness+'_'+_root.ncolor+'_'+fill+'-';circle(shapes[shapecount],startX,startY,endX,endY);
}else{
shapedata[shapecount]='circle_'+startX+'_'+startY+'_'+endX+'_'+endY+'_'+thickness+'_'+_root.ncolor+'_'+fill+'-';circle(shapes[shapecount],startX,startY,endX,endY);
}}
}
}
};
onMouseMove=function(){
// check if mouse is on the canvas
if(_ymouse<300){
// if pen tool is selected and drawing
if(_root.shape.text=='pen' && drawing==true){
// set line attributes and continue drawing
thickness=_root.linethickness.text;
shapelength=Math.sqrt(Math.pow(penX-_xmouse,2)+Math.pow(penY-_ymouse,2));
if(shapelength>5){
// only draw lines 5px or larger to prevent POST overload
shapecount++;
shapes[shapecount]='SMC_'+shapecount;
_root.createEmptyMovieClip(shapes[shapecount],1000+shapecount);
with(eval(shapes[shapecount])){moveTo(penX,penY);lineStyle(thickness,_root.ncolor);lineTo(_xmouse,_ymouse);}
shapedata[shapecount]='line_'+penX+'_'+penY+'_'+_xmouse+'_'+_ymouse+'_'+thickness+'_'+_root.ncolor+'_false-';
penX=_xmouse;
penY=_ymouse;
updateAfterEvent();
}}else{
// if any tool other than pen is selected
// create the temporary shape
if(drawing==true){
if(snapTo){endX=Math.floor(_xmouse/10)*10;}else{endX=_xmouse;}
if(snapTo){endY=Math.floor(_ymouse/10)*10;}else{endY=_ymouse;}
tracker.clear();
tracker.lineStyle(_root.linethickness.text,_root.ncolor);
tracker.moveTo(startX,startY);
if(_root.shape.text=='line'){tracker.lineTo(endX,endY);}
if(_root.shape.text=='curve'){curve('tracker',startX,startY,endX,endY);}
if(_root.shape.text=='rectangle'){rectangle('tracker',startX,startY,endX,endY);}
if(_root.shape.text=='circle'){circle('tracker',startX,startY,endX,endY);}
}
}
}
updateAfterEvent();
};
}
// end root event handlers
// create the canvas
_root.createEmptyMovieClip('canvas',1);
with(_root.canvas){
lineStyle(2);
moveTo(1,1);
lineTo(599,1);
lineTo(599,299);
lineTo(1,299);
lineTo(1,1);
}
// create the tracking movie clip
_root.createEmptyMovieClip('tracker',2000);
myformat=new TextFormat();
myformat.color=0x000000;
myformat.bullet=false;
myformat.font='Arial';
// create linethickness textfields
createTextField('linethicknessText',-1,0,295,55,40);
with(linethicknessText){
type='static';
multiline=true;
wordwrap=true;
selectable=false;
setTextFormat(_root.myformat);
text='Line Thickness';
}
createTextField('linethickness',3,40,295,15,20);
with(linethickness){
type='dynamic';
selectable=false;
setTextFormat(_root.myformat);
text=2;
_xscale=_yscale=150;
}
myformat.size=10;
// create drawing tool textfield
createTextField('shape',2,1,335,45,20);
shape.type='dynamic';
shape.selectable=false;
shape.multiline=false;
shape.wordWrap=false;
shape.setTextFormat(myformat);
shape.text='pen';
shape._xscale=shape._yscale=150;
// create fill status textfield
_root.createEmptyMovieClip('filler',4);
with(filler){
lineStyle(1,0x000000,1);
beginFill(0xffffff);
lineTo(40,0);
lineTo(40,50);
lineTo(0,50);
lineTo(0,0);
_x=5;_y=355;
}
_root.filler.onRollOver=function(){
_root.fillstatus.background=true;
_root.fillstatus.backgroundColor='0xc6c6c6';
};
_root.filler.onRollOut=function(){
_root.fillstatus.background=false;
};
_root.filler.onRelease=function(){
if(_root.fill){
_root.fillstatus.text='Fill '+_root.fill=false;
}else{
_root.fillstatus.text='Fill '+_root.fill=true;
}
};
createTextField('fillstatus',5,1,370,45,17);
fillstatus.type='dynamic';
fillstatus.selectable=false;
fillstatus.setTextFormat(myformat);
fillstatus.text='Fill '+fill;
fillstatus._xscale=fillstatus._yscale=150;
// create rgb color picker
_root.createEmptyMovieClip('cp',9500);
with(_root.cp){
_x=0;_y=330;
createEmptyMovieClip('bg',11);
with(bg){
lineStyle(1,0x000000);beginFill(0x000000);
lineTo(255/2+5,0);lineTo(255/2+5,14);lineTo(0,14);lineTo(0,0);
endFill();
}}
_root.cp.onMouseDown=function(){
if(hitTest(_root._xmouse,_root._ymouse,true) && _root.cp.r.hitTest(_root._xmouse,_root._ymouse,false)==false && _root.cp.g.hitTest(_root._xmouse,_root._ymouse,false)==false && _root.cp.b.hitTest(_root._xmouse,_root._ymouse,false)==false){
with(_root.cp){
startDrag(0,0,0,32,330);
}
}
};
_root.cp.onMouseUp=function(){
stopDrag();
};
_root.cp.onMouseMove=function(){
if(_root.cp.hitTest(_root._xmouse,_root._ymouse,false)){
this._xscale=200;
this._yscale=200;
_root.cb._visible=false;
}else{
this._xscale=30;
this._height=_root.linethickness.text;
this._yscale=Math.round(this._yscale);
this._x=0;
this._y=330-_root.linethickness.text/2;
_root.cb._visible=true;
stopDrag();
}
if(dragging){
rv=this.r._x*2+1;
gv=this.g._x*2+1;
bv=this.b._x*2+1;
rv=rv.toString(16).length<2?'0'+rv.toString(16):rv.toString(16);
gv=gv.toString(16).length<2?'0'+gv.toString(16):gv.toString(16);
bv=bv.toString(16).length<2?'0'+bv.toString(16):bv.toString(16);
_root.nc.setRGB('0x'+rv+gv+bv);
_root.ncolor='0x'+rv+gv+bv;
}
updateAfterEvent();
};
_root.cp._xscale=30;
_root.cp._yscale=20;
for(c=1;c<4;c++){
if(c==1){cv='r';cf='0xff0000';
}else{if(c==2){cv='g';cf='0x00ff00';
}else{cv='b';cf='0x0000ff';}}
_root.cp.createEmptyMovieClip(cv,c+9500);
with(eval('_root.cp.'+cv)){
lineStyle(0.25,0xffffff);
beginFill(cf);moveTo(0,-2);lineTo(5,-2);lineTo(5,2);lineTo(0,2);lineTo(0,-2);endFill();
_x=0;_y=c-3+c*4;
_root.cp[cv].onMouseDown=function(){
if(hitTest(_root._xmouse,_root._ymouse,false)){
drawing=false;
_root.dragging=true;
startDrag(0,0,_y,355/2,_y);
}
};
_root.cp[cv].onMouseUp=function(){
_root.dragging=false;
stopDrag();
};
}
}
_root.nc=new Color(_root.cp.bg);
// end rgb color picker
// create the buttons using getURL
// to post the data to the conversion scripts
_root.createTextField('convertText',9416,400,350,150,30);
with(convertText){
type='static';
border=false;
background=false;
selectable=false;
text='Convert Image To';
convertFormat=getTextFormat();
convertFormat.size=15;
convertFormat.align='center';
convertFormat.bold=true;
convertFormat.font='Arial';
convertFormat.color='0x0000ff';
setTextFormat(convertFormat);
}
_root.createEmptyMovieClip('convertJPGButton',9400);
with(convertJPGButton){
lineStyle(10,0x0000ff);
beginFill(0x0000ff);
lineTo(50,0);
lineTo(50,20);
lineTo(0,20);
lineTo(0,0);
_x=390;_y=375;
createTextField('convertJPGText',9401,0,0,50,30);
with(convertJPGText){
type='static';
border=false;
background=false;
selectable=false;
text='JPEG';
convertFormat=getTextFormat();
convertFormat.size=17;
convertFormat.align='center';
convertFormat.bold=true;
convertFormat.font='Arial';
convertFormat.color='0xffffff';
setTextFormat(convertFormat);
}
}
_root.convertJPGButton.onRelease=function(){
data='';
imagetype='jpg';
for(d=0;d<_root.shapedata.length;d++){
data+=_root.shapedata[d];
}
getURL('convert.php','_blank','POST');
};
_root.createEmptyMovieClip('convertPNGButton',9412);
with(convertPNGButton){
lineStyle(10,0x0000ff);
beginFill(0x0000ff);
lineTo(50,0);
lineTo(50,20);
lineTo(0,20);
lineTo(0,0);
_x=460;_y=375;
createTextField('convertPNGText',9413,0,0,50,30);
with(convertPNGText){
type='static';
border=false;
background=false;
selectable=false;
text='PNG';
convertFormat=getTextFormat();
convertFormat.size=17;
convertFormat.align='center';
convertFormat.bold=true;
convertFormat.font='Arial';
convertFormat.color='0xffffff';
setTextFormat(convertFormat);
}
}
_root.convertPNGButton.onRelease=function(){
data='';
imagetype='png';
for(d=0;d<_root.shapedata.length;d++){
data+=_root.shapedata[d];
}
getURL('convert.php','_blank','POST');
};
_root.createEmptyMovieClip('convertSWFButton',9414);
with(convertSWFButton){
lineStyle(10,0x0000ff);
beginFill(0x0000ff);
lineTo(50,0);
lineTo(50,20);
lineTo(0,20);
lineTo(0,0);
_x=530;_y=375;
createTextField('convertSWFText',9415,0,0,50,30);
with(convertSWFText){
type='static';
border=false;
background=false;
selectable=false;
text='SWF';
convertFormat=getTextFormat();
convertFormat.size=17;
convertFormat.align='center';
convertFormat.bold=true;
convertFormat.font='Arial';
convertFormat.color='0xffffff';
setTextFormat(convertFormat);
}
}
_root.convertSWFButton.onRelease=function(){
data='';
imagetype='swf';
for(d=0;d<_root.shapedata.length;d++){
data+=_root.shapedata[d];
}
getURL('convert.php','_blank','POST');
};
// create buttons for drawing tools
_root.createEmptyMovieClip('lineButton',9402);
with(lineButton){
lineStyle(1,0x000000,1);
beginFill(0xffffff);
lineTo(20,0);
lineTo(20,20);
lineTo(0,20);
lineTo(0,0);
endFill();
lineStyle(1,0x000000);
moveTo(20,0);
lineTo(0,20);
_x=200;_y=305;
_xscale=_yscale=200;
}
_root.lineButton.onRelease=function(){
if(_root.cp._xscale<200){
_root.shape.text='line';
_root.highlighter._x=200;
}
};
_root.createEmptyMovieClip('curveButton',9403);
with(curveButton){
lineStyle(1,0x000000,1);
beginFill(0xffffff);
lineTo(20,0);
lineTo(20,20);
lineTo(0,20);
lineTo(0,0);
endFill();
lineStyle(1,0x000000);
curveTo(20,0,20,20);
_x=300;_y=305;
_xscale=_yscale=200;
}
_root.curveButton.onRelease=function(){
if(_root.cp._xscale<200){
_root.shape.text='curve';
_root.highlighter._x=300;
}
};
_root.createEmptyMovieClip('rectButton',9404);
with(rectButton){
lineStyle(1,0x000000,1);
beginFill(0xffffff);
lineTo(20,0);
lineTo(20,20);
lineTo(0,20);
lineTo(0,0);
endFill();
lineStyle(1,0x000000);
lineTo(20,0);
lineTo(20,20);
lineTo(0,20);
lineTo(0,0);
_x=400;_y=305;
_xscale=_yscale=200;
}
_root.rectButton.onRelease=function(){
if(_root.cp._xscale<200){
_root.shape.text='rectangle';
_root.highlighter._x=400;
}
};
_root.createEmptyMovieClip('circleButton',9405);
with(circleButton){
lineStyle(1,0x000000,1);
beginFill(0xffffff);
lineTo(20,0);
lineTo(20,20);
lineTo(0,20);
lineTo(0,0);
endFill();
moveTo(10,10);
lineStyle(1,0x000000);
x=y=a=b=10;
j=a*0.70711;
n=b*0.70711;
i=j-(b-n)*a/b;
m=n-(a-j)*b/a;
moveTo(x+a,y);
curveTo(x+a,y-m,x+j,y-n);
curveTo(x+i,y-b,x,y-b);
curveTo(x-i,y-b,x-j,y-n);
curveTo(x-a,y-m,x-a,y);
curveTo(x-a,y+m,x-j,y+n);
curveTo(x-i,y+b,x,y+b);
curveTo(x+i,y+b,x+j,y+n);
curveTo(x+a,y+m,x+a,y);
_x=500;_y=305;
_xscale=_yscale=200;
}
_root.circleButton.onRelease=function(){
if(_root.cp._xscale<200){
_root.shape.text='circle';
_root.highlighter._x=500;
}
};
_root.createEmptyMovieClip('penButton',9406);
with(penButton){
lineStyle(1,0x000000,1);
beginFill(0xffffff);
lineTo(20,0);
lineTo(20,20);
lineTo(0,20);
lineTo(0,0);
endFill();
lineStyle(1,0x000000);
moveTo(0,3);
beginFill(0xc6c6c6);
lineTo(3,0);
lineTo(6,3);
lineTo(3,6);
lineTo(0,3);
endFill();
lineStyle(1,0x000000);
beginFill(0x000000);
moveTo(6,3);
lineTo(20,17);
lineTo(17,20);
lineTo(3,6);
lineTo(6,3);
endFill();
lineStyle(0.5,0x000000);
beginFill(0xffffff);
moveTo(20,17);
lineTo(20,20);
lineTo(17,20);
lineTo(20,17);
endFill();
_x=100;_y=305;
_xscale=_yscale=200;
}
_root.penButton.onRelease=function(){
if(_root.cp._xscale<200){
_root.shape.text='pen';
_root.highlighter._x=100;
}
};
_root.createEmptyMovieClip('clearButton',9407);
with(clearButton){
lineStyle(1,0x000000,1);
beginFill(0xffffff);
lineTo(45,0);
lineTo(45,20);
lineTo(0,20);
lineTo(0,0);
endFill();
_x=110;_y=350;
_xscale=_yscale=200;
createTextField('clearAllText',9408,0,3,50,17);
with(clearAllText){
type='static';
border=false;
background=false;
text='Clear All';
clearFormat=getTextFormat();
clearFormat.size=10;
clearFormat.bold=true;
setTextFormat(clearFormat);
}
}
_root.clearButton.onRollOver=function(){
_root.clearButton.clearAllText.background=true;
_root.clearButton.clearAllText.backgroundColor='0xc6c6c6';
};
_root.clearButton.onRollOut=function(){
_root.clearButton.clearAllText.background=false;
};
_root.clearButton.onRelease=function(){
if(_root.cp._xscale<200){
for(sc=0;sc<_root.shapes.length;sc++){
removeMovieClip(shapes[sc]);
}
_root.shapes=new Array();
_root.shapedata=new Array();
if(drawing && shape=='pen'){
moveTo(_xmouse,_ymouse);
}
drawing=false;_root.tracker.clear();
}
};
_root.createEmptyMovieClip('clearLastButton',9409);
with(clearLastButton){
lineStyle(1,0x000000,1);
beginFill(0xffffff);
lineTo(50,0);
lineTo(50,20);
lineTo(0,20);
lineTo(0,0);
endFill();
_x=250;_y=350;
_xscale=_yscale=200;
createTextField('clearLastText',9410,0,3,50,17);
with(clearLastText){
type='static';
border=false;
background=false;
text='Clear Last';
clearFormat=getTextFormat();
clearFormat.size=10;
clearFormat.bold=true;
setTextFormat(clearFormat);
}
}
_root.clearLastButton.onRollOver=function(){
_root.clearLastButton.clearLastText.background=true;
_root.clearLastButton.clearLastText.backgroundColor='0xc6c6c6';
};
_root.clearLastButton.onRollOut=function(){
_root.clearLastButton.clearLastText.background=false;
};
_root.clearLastButton.onRelease=function(){
if(_root.cp._xscale<200){
if(_root.shapecount>0){
removeMovieClip(_root.shapes[_root.shapecount]);
_root.shapes[_root.shapecount]='';
_root.shapedata[_root.shapecount]='';
_root.shapecount--;
}
}
};
_root.createEmptyMovieClip('highlighter',9411);
with(highlighter){
lineStyle(1,0x000000,10);
beginFill(0x000000,20);
lineTo(20,0);
lineTo(20,20);
lineTo(0,20);
lineTo(0,0);
endFill();
moveTo(0,20);
lineStye(2,0x000000);
lineTo(20,20);
_xscale=_yscale=200;
_x=100;_y=305;
}
_root.clear();
stop();