A Simple Drawing Application and a Quick Glance at Safari
Taking a well-deserved break from the Navy and coming home to Ireland, I had a little time to put together a small example of what may be accomplished with the UI tools from my last post. Here’s a simple little drawing application that allows the user to adjust the size, color and shape of the drawing tool. It’s easily enough created by instantiating a new DrawingTablet instance and passing the width, height, and color of the canvas as arguments. A fourth Boolean argument determines whether or not a “save” button is shown. Note that in this example, the save button doesn’t really do anything. In actual use, a BitmapData instance of the drawing would be passed to a DrawingEvent.SAVE event which could then be passed on to an image encoder (such as the ones included in Adobe’s as3corelib package which may be downloaded from Google Code, here).
So, for a quick example, the following document class may be used to create the .swf file below:
package { import com.onebyonedesign.drawing.DrawingTablet; import com.onebyonedesign.drawing.events.DrawingEvent; import flash.display.Sprite; /** * Document class to illustrate com.onebyonedesign.drawing package * @author Devon O. */ public class Test extends Sprite { private var tablet:DrawingTablet; public function Test():void { init(); } private function init():void { createTablet(); } private function createTablet():void { tablet = new DrawingTablet(300, 300, 0xFFFFCC); tablet.addEventListener(DrawingEvent.SAVE, onSave); tablet.x = 20; tablet.y = 20; addChild(tablet); } private function onSave(de:DrawingEvent):void { // de.image is a BitmapData instance which may then be passed to image encoder. } } }
The .as files may be downloaded here for any interested parties.
[kml_flashembed movie=”http://blog.onebyonedesign.com/wp-content/uploads/2008/04/drawingapp.swf” height=”340″ width=”365″ /]
In other news, I was surfing the other day when suddenly my Apple Updater popped up in front of me. An annoying little event that normally means it’s time to update Quicktime or Itunes. This time, however, I was told I needed to update my Safari browser. Being a PC/Windows user, I figured this was a glitch. Turns out it wasn’t though. Safari is now available for Windows. I tried it out. Doesn’t seem to be a bad browser really, but it doesn’t allow for mousewheel interaction. I realize there’s no such thing in the Mac world, but as long as you’re developing for a new environment, why not make use of all available API’s. Personally, I’ll stick to IE (yes, I use IE) for most cases, but it’s nice to throw another browser into the testing stage mix when developing web based material.
EDIT: Okay, so it is only the Flash player running in the Safari browser that doesn’t receive the mousewheel events. The mousewheel will trigger events within “regular” html pages.