I've figured out a roundabout solution myself. I created 2 canvases
(one a normal canvas, and another a class that extended ui component
that can hold sprites). 

I called the normal canvas 'canvas' and the ui component class 'canvas_ui'

I drew on 'canvas' using canvas.graphics.lineTo(x, y) and recorded
points in an array I called lineCoordinates.

when the line is finished i.e. using mouse move functions etc, I added
a sprite to the canvas_ui and looped through the array with lineTo
commands thus replicating the line on the other canvas. I then cleared
the graphics from the first canvas and reset the lineCoordinates (
lineCoordinates = new Array() ). 

Using a spriteNum variable, I increment it by one every time a new
sprite is added.  

The point of this is so I can delete lines with an undo button that
basically says canvas_ui.removeChildAt(spriteNum). I then decrement
spriteNum by one.

This is roundabout but it works. if anyones got a simpler solution I'm
happy to hear it.



--- In [email protected], "philza1985"
<[EMAIL PROTECTED]> wrote:
>
> Does anyone know of any tutorials creating a drawing application with
> an undo function like the graffiti application on facebook.
> 
> I've been trying to add a sprite to a drawing canvas ui component
> class which is successful as follows, 
> 
> 
> ----------------------------------
> private function beginLine():void 
> {
> var sprite:Sprite = new Sprite;
>                       
> sprite.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
> sprite.addEventListener(MouseEvent.MOUSE_UP, onEndLine);
>             
> dwg_canvas.addChild(sprite);
> 
> sprite.graphics.moveTo(mouseX, mouseY);
> sprite.graphics.lineStyle(lineWidth, lineColor, 1);
> sprite.graphics.lineTo(mouseX+1, mouseY); // this draws a dot
> }
> ----------------------------------
> 
> 
> but when I create an EventListener on the sprite it doesn't go into
> the mouseMove function which says
> 
> 
> ----------------------------------
> private function onMouseMove(event:MouseEvent):void 
> {
> event.target.graphics.lineTo(mouseX, mouseY);
> }
> -----------------------------
> 
> 
> the plan is to have all these sprites created then store the number in
> the modelLocator so that in order to undo I just have to say
> 
> dwg_canvas.removeChildAt(spriteNum);
> 
> Again the main thing is not the code but just to get a basic undo
> function working, so if anyone out there has any tutorials, that would
> be great. 
> 
> thanks.
>


Reply via email to