Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

simple drawing program AS3.0

Mentor ,
Jan 09, 2010 Jan 09, 2010

I have a drawing program that doesn't behave the way I expect:

var myShape:Shape = new Shape();
myShape.graphics.moveTo(mouseX,mouseY);
myShape.graphics.lineStyle(1, 0xFF0000);


//stage.addEventListener(MouseEvent.MOUSE_DOWN,startdraw);



stage.addEventListener(MouseEvent.MOUSE_DOWN, startdraw);
stage.addEventListener(MouseEvent.MOUSE_UP,stopdraw);

function startdraw(myevent:MouseEvent):void{
stage.addEventListener(MouseEvent.MOUSE_MOVE, draws);
myShape.graphics.lineTo(mouseX, mouseY);

myevent.updateAfterEvent();



}
function stopdraw(myevent:MouseEvent):void{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, draws);
}
function draws(myeventd:MouseEvent):void{
addChild(myShape);
}

I would like the Flash to recognize that the mouse is down and continue drawing while it is down.  Currently it only draws if the mouse is clicked, even while it is down it does not draw.  Once I click the mouse and it sends a signal that it has gone down it draws a straight line from the last point that it was clicked rather than drawing continuously.

TOPICS
ActionScript
4.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 09, 2010 Jan 09, 2010

try:

var myShape:Shape = new Shape();
myShape.graphics.lineStyle(1, 0xFF0000);

//stage.addEventListener(MouseEvent.MOUSE_DOWN,startdraw);

stage.addEventListener(MouseEvent.MOUSE_DOWN, startdraw);
stage.addEventListener(MouseEvent.MOUSE_UP,stopdraw);

function startdraw(myevent:MouseEvent):void {
    myShape.graphics.moveTo(mouseX,mouseY);
    stage.addEventListener(MouseEvent.MOUSE_MOVE, draws);
}
function stopdraw(myeventb:MouseEvent):void {
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, draws);
}
func

...
Translate
Mentor ,
Jan 09, 2010 Jan 09, 2010

I fixed it.  Thanks anyway.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 09, 2010 Jan 09, 2010

No, I didn't fix it.  Now it draws and stops when the mouse is up, but there is a line joining the last mouse position to the new mouse position instead of there being a break in the curve.

var myShape:Shape = new Shape();
myShape.graphics.moveTo(mouseX,mouseY);
myShape.graphics.lineStyle(1, 0xFF0000);


//stage.addEventListener(MouseEvent.MOUSE_DOWN,startdraw);



stage.addEventListener(MouseEvent.MOUSE_DOWN, startdraw);
stage.addEventListener(MouseEvent.MOUSE_UP,stopdraw);

function startdraw(myevent:MouseEvent):void{
stage.addEventListener(MouseEvent.MOUSE_MOVE, draws);



}
function stopdraw(myeventb:MouseEvent):void{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, draws);

}
function draws(myeventd:MouseEvent):void{

myShape.graphics.lineTo(mouseX, mouseY);

myeventd.updateAfterEvent();

addChild(myShape);
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 09, 2010 Jan 09, 2010

I fixed it again for good.  I had to add:

myShape.graphics.moveTo(mouseX,mouseY);

after the last line within the function startdraw();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2010 Jan 09, 2010

try:

var myShape:Shape = new Shape();
myShape.graphics.lineStyle(1, 0xFF0000);

//stage.addEventListener(MouseEvent.MOUSE_DOWN,startdraw);

stage.addEventListener(MouseEvent.MOUSE_DOWN, startdraw);
stage.addEventListener(MouseEvent.MOUSE_UP,stopdraw);

function startdraw(myevent:MouseEvent):void {
    myShape.graphics.moveTo(mouseX,mouseY);
    stage.addEventListener(MouseEvent.MOUSE_MOVE, draws);
}
function stopdraw(myeventb:MouseEvent):void {
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, draws);
}
function draws(myeventd:MouseEvent):void {
    myShape.graphics.lineTo(mouseX, mouseY);
    myeventd.updateAfterEvent();
    addChild(myShape);
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 13, 2012 Aug 13, 2012

Any chance the drawing could be saved as a sharedobject so when the user re-opens the SWF, the drawing is intact and the user can continue? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 13, 2012 Aug 13, 2012

you can save the data used to create the drawing so the drawing can be recreated but you can't directly save the drawing to a shared object.

you can save the drawing (as a bitmap) if the swf is on a server that can use server-side code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 11, 2012 Oct 11, 2012
LATEST

I have exactly the same problem as crazy90210, I want to create a drawing pad where anyone can draw and it stays as a common art work among users.

Now I know very little about flash and this is the first thing that I am tring to do. My drawing pad works perfectly, but I don't know how to save it. I thought you could use remote shared object, why is tho not possible? (as I said, I know very little)

and umm, what does this mean:

you can save the drawing (as a bitmap) if the swf is on a server that can use server-side code


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines