Draw illustration with Flash AS3

Hello.  I am planning to create a drawing game with ActionScript 3.  Here's my idea.  I will create some buttons with color, i.e., red, blue, green, yellow and white.  When I click one of them, I can start drawing with the color I choose on the stage.  Also, I will crate an eraser button, so once someone finishs her/his drawings, you can clean the stage and start over.

This is something I thought about it may work, but obviously, it doesn't work...  

Does anyone kindly help me what I am doing wrong?  I appreciate your help!
//create a button, instance name is redButton
var newLine1:Shape = new Shape();
addChild(newLine1);
redButton.addEventListener(MouseEvent.MOUSE_DOWN, drawRed);
redButton.addEventListener(MouseEvent.MOUSE_MOVE, moveRed);
redButton.addEventListener(MouseEvent.MOUSE_UP, quitRed);
function drawRed(event:MouseEvent):void
{
	newLine1.graphics.lineStyle(3);
	newLine1.graphics.beginFill(0xCC0000);
}
function moveRed(event:MouseEvent):void
{
	newLine1.graphics.lineTo(mouseX, mouseY);
}
function quitRed(event:MouseEvent):void
{
	newLine1.graphics.endFill();
}
 
 
 
btnClear.addEventListener(MouseEvent.MOUSE_DOWN, clearStage);
function clearStage(event:MouseEvent):void
{
	stage.graphics.clear();
}

Open in new window

sabregirlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rascalpantsCommented:

at first glance, you probably should be creating a new line and using addChild() with each time you run the draw functions...

try doing that...



rp / ZA
0
sabregirlAuthor Commented:
Hello rascalpants,
     Thank you for your help.  Unfortunately, it didn't work...

     One mistake that I realiezd is that for the clear button, I need to use "newLine1" instead of "stage", which is working properly now...

     
btnClear.addEventListener(MouseEvent.MOUSE_DOWN, clearStage);
function clearStage(event:MouseEvent):void
{
        newLine1.graphics.clear();
}

Open in new window

0
rascalpantsCommented:

well, typically when you create a drawing application, you want to create a new instance of a line/shape with each stroke, much like Photoshop or Drawing with Flash.  The reason for this is to be able to undo strokes, and also to be able to delete ceretain areas without completely starting over...

can you explain a little better, what part of the code doesn't work?

rp / ZA
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

sabregirlAuthor Commented:
Hello rascalpants,
     Thank you for your comment.  My current problem is that I simply am not drawing anything.

     Also, I think I understand the concept of addChild().  That's why I added that code at the beginning, since I set up running ActionScript from top to bottom...

     
0
blue-genieCommented:
sabregirl.
it doesn't help you to add the object - and then you change it with the lineTo etc, but you don't update it to the stage. just implement what rp says and you'll see that you'll end up with a line from  0.0  to where you clicked your button. you'll need to tweak it but at least you'll be "drawing something".
0
sabregirlAuthor Commented:
Hello blue-genie.  Thank you for your comment.  Would you let me know how I should "tweak" this code?  Thank you for your help.
0
blue-genieCommented:
you'll see what i mean by tweaking when you apply the addChild(). you need to specify where it starts drawing.
you need to tweek the start position based on what you're trying to achieve.
try getting it to draw and work first.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.