Flash® 8 - PixelEdit Version 1 by Ted Patrick
I made this Pixel Editor using the new flash.display.BitmapData class. The PixelEdit project will be released over time as I add features and each version will remain available in Flash® By Example. Ideally you will see the project evolve over time as I solve problems, recompile, and refactor.
The new flash.display.BitmapData class represents an Image in player memory. To display an instance of this class, you use MovieClip.attachBitmap to make the instance appear on the stage. In PixelEdit I have used attachBitmap twice to provide the editing view and the preview view. As both reference the same BitmapData instance, as I make changes to the BitmapData, the view is updated on both automatically. You can actually have N views of a BitmapData active on stage at one time. Depending on the editors state (Pen or Eraser) drawing on the editing view will have different effects. Currently the states are hardwired into the editing view but we will make these class based in a later build. The editing of the BitmapData is done using the new setPixel method in conjunction with coordinates and a color. 'setPixel' is very fast and allows you to rapidly modify BitmapData. As you can see from the example there is no delay in the drawing tools.
The goal for this version was not to make the best pixel editor but to get simple version working. The code was not designed very well as I was focused on getting to basic functionality. Working this way, I learned some lessons about using the new classes and discovered some core problems with events. I will take these lessons into the next version and apply a pattern that will make development much easier. Ideally these changes will give me the headroom needed to add higher level editing tools while simplifying the design.
I adhere to the "Throw one Away" mentality during early developing as I never get things correct on the first try, who does? With every project I work on I plan to throw a release away and learn from it. At this early stage it is a waste of time and energy for me to invest heavily in design and OOP. I planned to learn some lessons and get to a working application as quickly as possible. This stage took me about 2.5 hours and included writing a ColorPicker component. I probably shouldn't have written the component but I knew I would need it downstream. This is not to say that design and OOP are not important but to actually design something you need to understand the problem at hand. As things evolve I will use classes to refactor and rebuild the editor into a more reusable format.
If you have any feature suggestions for PixelEdit, please post them into the comments below. Happy pixel editing!
This example is available with full source and documentation within Flash® by Example.
More to come.
Ted :)
0 Comments:
Post a Comment
<< Home