View Full Version : erasing a shape
DanglingChap
03-13-2008, 12:21 PM
I have creating a shape at each frame using frameevent .. the movie runs for almost 1900 frames and at the end the movie start repeating ..
I want to know how can i erase the already drawn shape after the last frame of the movie, so that on repeating it start drawing new one ..
lordofduct
03-13-2008, 12:36 PM
if you are reusing the same shape... just clear the data out of the shape with:
myShape.graphics.clear();
if you create a brand new shape each time the timeline loops... then you'd have to kill the shape by clear out its graphics, removing it from the parent displayContainer, and setting it to null.
I'd suggest for cleaner code and better memory management to create a single instance of the shape independent of the frames, then update the shape along the timeline and clearing the graphics at the last frame like my first sentence says.
I'm not sure how this is done in the action panel, as I use .as files always. But I did this and it worked in an action panel:
var myShape:Shape;
if (!myShape){
myShape = new Shape();
addChild(myShape);
}
... animation code
DanglingChap
03-13-2008, 12:46 PM
if you are reusing the same shape... just clear the data out of the shape with:
myShape.graphics.clear();
if you create a brand new shape each time the timeline loops... then you'd have to kill the shape by clear out its graphics, removing it from the parent displayContainer, and setting it to null.
I'd suggest for cleaner code and better memory management to create a single instance of the shape independent of the frames, then update the shape along the timeline and clearing the graphics at the last frame like my first sentence says.
oh, thanks. I was also looking for such a method and it really works @ your first approach.
emm, I have a movie clip, in which there is embeded flv file. i have writen code @ first frame of the movie clip and in last frame i have "stop" .. and a mouse so that on click it plays the movie again.
but it's ain't working ..
stop();
this.btnPlay.addEventListener(MouseEvent.CLICK, onMouseClickEvent);
function onMouseClickEvent(event:MouseEvent):void {
if(event.buttonDown){
clean();
}
}
function clean():void{
this.idealLine.graphics.clear();
this.deviLine.graphics.clear();
this.gotoAndPlay(1);
}
why i am not able to goto @ first frame of the movieclip which contain flv file.
all this code is in movieclip timeline
lordofduct
03-13-2008, 12:59 PM
MouseEvent.CLICK does not register until the mouse button has been released. So when you are checking if the mouse button is down, it isn't, it has been released already.
there is no need to have that check for if the mouse button is down.
put this for your onMouseClickEvent
function onMouseClickEvent(event:MouseEvent):void {
clean();
trace("clicked");
}
watch your output window and you'll see it happens when you let off the mouse button.
DanglingChap
03-13-2008, 01:06 PM
MouseEvent.CLICK does not register until the mouse button has been released. So when you are checking if the mouse button is down, it isn't, it has been released already.
there is no need to have that check for if the mouse button is down.
put this for your onMouseClickEvent
function onMouseClickEvent(event:MouseEvent):void {
clean();
trace("clicked");
}
watch your output window and you'll see it happens when you let off the mouse button.
cool, it worked ... THANKS A LOT! ..
but i am not able to understand the reason you gave about mouse event registration .. can you elaborate.
lordofduct
03-13-2008, 01:13 PM
There are several different mouseEvents. the one called MouseEvent.CLICK registers when you've have actually clicked the mouse.
A click isn't the action of pushing down though, it is the action of pushing down and releasing of the button on your mouse. Thus the event does not fire until after you've actually released the button of the mouse... thusly if you check for the button state, it is going to be false... because you've already released it.
I'm assuming you had that boolean check to make sure you've actually click the mouse. If you are reusing a function for whatever reason, you can check which MouseEvent has fire with:
function onMouseEvent(event:MouseEvent):void {
if (event.type == MouseEvent.CLICK) {
//this checked to make sure the event was actually a mouse click
}
}
DanglingChap
03-13-2008, 01:44 PM
There are several different mouseEvents. the one called MouseEvent.CLICK registers when you've have actually clicked the mouse.
A click isn't the action of pushing down though, it is the action of pushing down and releasing of the button on your mouse. Thus the event does not fire until after you've actually released the button of the mouse... thusly if you check for the button state, it is going to be false... because you've already released it.
I'm assuming you had that boolean check to make sure you've actually click the mouse. If you are reusing a function for whatever reason, you can check which MouseEvent has fire with:
function onMouseEvent(event:MouseEvent):void {
if (event.type == MouseEvent.CLICK) {
//this checked to make sure the event was actually a mouse click
}
}
a humble thanks for the explanation .. :) .. THANKS A LOT
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.