Copy link to clipboard
Copied
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);
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
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Alright, i'll try to work this out. Thanks for helping kglad. i really appreaciate your effort.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now