29 September 2006

Choose the Right Tool for the Job

Written by Richard Leggett ( Contact the author of this post )
Published on September 29th, 2006 @ 08:52:05 am, using 335 words, 334 views
Categories: Flash

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):


Comments, Pingbacks:

Comment from: Aral Balkan
Hey Rich,

That's so funny -- I just fired up Flex Builder to churn this out in AS3 :) Thanks for beating me to it, now I have more time for WoW!
PermalinkPermalink 30/09/06 @ 05:50
Comment from: Richard Leggett [Member] Email
Haha, oh no! I've done you no favours with extra WoW time.
PermalinkPermalink 30/09/06 @ 05:56
Comment from: Aral Balkan
Hey, btw, a SWF demo would rock so that people can compare the visual result and performance of the two.
PermalinkPermalink 30/09/06 @ 06:05
Comment from: Richard Leggett [Member] Email
Consider it done. Talking of performance, I could only draw a few tens of lines before the Javascript version killed my machine, looks like there's probably a memory leak somewhere in those reams of code.

This is a Flash 6 version. Not using the bitmap capabilities of Flash 8+ to allow for a lot more stuff. But hey, using a bit of physics can make for a truly addictive little game:

http://www.deviantart.com/deviation/40255643/
PermalinkPermalink 30/09/06 @ 06:20
Comment from: Tink
Ideally you'd add a couple of more lines and draw it onto a BitmapData object each time the mouse is released to keep performance at a peak.
PermalinkPermalink 30/09/06 @ 14:20
Comment from: sascha/hdrs
Funny to see how they use JavaScript to make such a crappy App but then have annoying Ad Banners made with Flash at the bottom of their page! Don't you love such people?!
PermalinkPermalink 30/09/06 @ 21:19
Comment from: Phillip Kerman
26 lines if you take out that last line... still works.
PermalinkPermalink 01/10/06 @ 10:17
Comment from: Richard Leggett [Member] Email
All good comments guys! I think we could boil this down to 15 lines if you spent a little while on it, but that would defeat the object here of saving time ;)
PermalinkPermalink 01/10/06 @ 10:26

Comments are closed for this post.

About

Richard Leggett is a Freelance RIA and Web Developer (download CV, skills/portfolio coming soon). He is co-author of Foundation Flash Applications for Mobile Devices (Friend of ED), an Adobe Community Expert and speaker at industry conferences and user groups.



July 2008
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Categories

Miscellany

XML Feeds

Information

Contact the admin  /   b2evo template by Two18 Media