29 September 2006
Choose the Right Tool for the Job
Published on September 29th, 2006 @ 08:52:05 am, using 335 words, 334 views
I just came across this Doodle Javascript app on MXNA. Mistakenly I said to colleagues, anyone could do that in under a minute in Flash. This was met with the obvious, OK go on then. Instead of getting a really bad looking jagged-lined, clunky drawing tool using 5 Javascript libraries (that don't even work in Safari I am told), you could just plug in 27 very basic lines of code into Flash...
createEmptyMovieClip("bufferMC", 1);
var mousedown = false;
var origX = 0;
var origY = 0;
function onMouseDown() {
origX = _xmouse;
origY = _ymouse;
moveTo(_xmouse, _ymouse);
lineStyle(1, 0, 100);
bufferMC.clear();
mousedown = true;
}
function onMouseUp() {
lineTo(_xmouse, _ymouse);
bufferMC.clear();
mousedown = false;
}
function onMouseMove() {
if (mousedown) {
bufferMC.clear();
bufferMC.lineStyle(1, random(0xFFFFFF), 100);
bufferMC.moveTo(origX, origY);
bufferMC.lineTo(_xmouse, _ymouse);
updateAfterEvent();
}
}
Mouse.addListener(this);
Now I am very much keen to advise using HTML and Javascript when it is the obvious choice. But what gets me is when people go out of their way to make technologies do things that others clearly do a lot more naturally. Hence this blog is HTML, so I always think to myself, choose the right technology for the job and don't create work for yourself! ![]()
As a bonus the fact that Flash is made for this sort of thing brings with it some nice extras, you might notice that with 2 seconds of extra effort here we have the line colour changing as you move until you release, or why not comment out the 3 lines that say bufferMC.clear() and see what you get.
Sample (345 bytes):
