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

Reset graphics

New Here ,
Nov 29, 2013 Nov 29, 2013

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);

TOPICS
ActionScript
946
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 , Nov 29, 2013 Nov 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.grap

...
Translate
Community Expert ,
Nov 29, 2013 Nov 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);

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 ,
Nov 29, 2013 Nov 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.

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 ,
Nov 29, 2013 Nov 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?

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 ,
Nov 29, 2013 Nov 29, 2013

I thought by using the 'reset' variable, i can do something like this:

var reset = true;

btnReset.addEventListener(MouseEvent.CLICK,doReset);

function doReset (e) {

    if (reset==true) {   

    myMc.graphics.clear();    //if i click on the reset btn, it clears the lines

     }

    if (reset==false) (e) {

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

    myMc.graphics.moveTo(myPencil.x, myPencil.y);  //if i didn't click on it, i can draw normally

}

But i guess it doesn't work that way.

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
Adobe Employee ,
Nov 29, 2013 Nov 29, 2013

The point that kglad makes here is that the variable 'reset' is not required. Since you've attached a click handler on the reset button (doReset), the function would be called whenever you click the reset button. You already know that reset button was clicked, so no need to have any other state variable checking if reset button was clicked.

-Dharmendra

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 ,
Nov 29, 2013 Nov 29, 2013

no, it doesn't.

but look at the wasReset variable i used.  it is used in doDraw to move the start draw point when the stage is clicked.

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 ,
Dec 01, 2013 Dec 01, 2013

Alright, i'll try to work this out. Thanks for helping kglad. i really appreaciate your effort.

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 ,
Dec 01, 2013 Dec 01, 2013
LATEST

you're welcome.

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