Skip to main content
Participant
November 29, 2013
Answered

Reset graphics

  • November 29, 2013
  • 1 reply
  • 1012 views

Hi, I would like to know how to reset a graphic by maintaining the current position of my animated movie clip which is attached to the line. I only want the lines to be removed. But I don't know why it doesn't work. When i clicked on the reset button, the animated MC just followed and moved to the reset button. Oh and after i reset it, I want it to be able to draw lines again. And i tried the removing and re-adding the eventListener but i don't really know how to make it more dynamic. I'm confused.I really need help. Thanks Here's my code:

import fl.transitions.Tween;

import fl.transitions.easing.*;

import fl.transitions.TweenEvent;

var reset = true;

btnReset.addEventListener(MouseEvent.CLICK,doReset);

function doReset (e) {

    if (reset==true) {   

    myMc.graphics.clear();

    myMc.graphics.lineStyle(2, 0xff6644, .75);

    myMc.graphics.moveTo(myPencil.x, myPencil.y);

    }

   

}

myMc.graphics.lineStyle(2, 0xff6644, .75);

myMc.graphics.moveTo(myPencil.x, myPencil.y);

function doDraw (e) {

    myMc.graphics.lineTo(myPencil.x, myPencil.y);

}

function startDraw (e) {

    var myTween:Tween = new Tween(myPencil, "x", Regular.easeOut, myPencil.x, mouseX, 1, true);

    var myTween2:Tween = new Tween(myPencil, "y", Regular.easeOut, myPencil.y, mouseY, 1, true);

    myTween2.addEventListener(TweenEvent.MOTION_CHANGE, doDraw);

   

}

stage.addEventListener(MouseEvent.CLICK, startDraw);

This topic has been closed for replies.
Correct answer kglad

you could solve one problem by using:

import fl.transitions.Tween;

import fl.transitions.easing.*;

import fl.transitions.TweenEvent;

var reset = true;  // it's not clear this is correct because i don't see it being set to false anywhere

var wasReset:Boolean;

btnReset.addEventListener(MouseEvent.CLICK,doReset);

function doReset (e) {

    if (reset==true) {   

    myMc.graphics.clear();

    myMc.graphics.lineStyle(2, 0xff6644, .75);

wasReset=true;

    }

   

}

myMc.graphics.lineStyle(2, 0xff6644, .75);

myMc.graphics.moveTo(myPencil.x, myPencil.y);

function doDraw (e) {

if(wasReset){

    myMc.graphics.moveTo(myPencil.x, myPencil.y);

wasReset=false;

}

    myMc.graphics.lineTo(myPencil.x, myPencil.y);

}

function startDraw (e) {

    var myTween:Tween = new Tween(myPencil, "x", Regular.easeOut, myPencil.x, mouseX, 1, true);

    var myTween2:Tween = new Tween(myPencil, "y", Regular.easeOut, myPencil.y, mouseY, 1, true);

    myTween2.addEventListener(TweenEvent.MOTION_CHANGE, doDraw);

   

}

stage.addEventListener(MouseEvent.CLICK, startDraw);

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
November 29, 2013

you could solve one problem by using:

import fl.transitions.Tween;

import fl.transitions.easing.*;

import fl.transitions.TweenEvent;

var reset = true;  // it's not clear this is correct because i don't see it being set to false anywhere

var wasReset:Boolean;

btnReset.addEventListener(MouseEvent.CLICK,doReset);

function doReset (e) {

    if (reset==true) {   

    myMc.graphics.clear();

    myMc.graphics.lineStyle(2, 0xff6644, .75);

wasReset=true;

    }

   

}

myMc.graphics.lineStyle(2, 0xff6644, .75);

myMc.graphics.moveTo(myPencil.x, myPencil.y);

function doDraw (e) {

if(wasReset){

    myMc.graphics.moveTo(myPencil.x, myPencil.y);

wasReset=false;

}

    myMc.graphics.lineTo(myPencil.x, myPencil.y);

}

function startDraw (e) {

    var myTween:Tween = new Tween(myPencil, "x", Regular.easeOut, myPencil.x, mouseX, 1, true);

    var myTween2:Tween = new Tween(myPencil, "y", Regular.easeOut, myPencil.y, mouseY, 1, true);

    myTween2.addEventListener(TweenEvent.MOTION_CHANGE, doDraw);

   

}

stage.addEventListener(MouseEvent.CLICK, startDraw);

Participant
November 29, 2013

Hi, Kglad thanks for replying. Sad to say but  the Animated Mc and the line still gets drawn when i clicked on the reset button. I think something went wrong in my script.

kglad
Community Expert
Community Expert
November 29, 2013

drawing will continue until you remove that stage listener.  so, if you want to stop drawing remove that listener.

you said you wanted to reset the drawing.  i understand that to mean you want to "erase" whatever's been drawn.  that's what calling doReset should do.  also, what's the purpose of the 'reset' variable?