Reputation: 43
Hi I have made an code so if you click on an object the object dissapears and for that I used this code:
flap1.visible = false;
but the object needs to stay false during the whole animation
Upvotes: 0
Views: 2297
Reputation: 2558
Flash timelines are kind of like a static state machine; moving from frame-to-frame will run all of the document code at that frame (every time). It also resets the value of the content to the state it was in during design time (so, frame = design + code). Because of the headaches this model can cause, I highly recommend you do all of your design & code in a single frame. In short, don't use timelines.
If you're not ready to make the shift, and want to make sure it stays hidden, you'll need to set the visibility of flap1
at each frame. This might look something like this:
function toggleBtnListener(e:MouseEvent):void {
if (flap1.visible) {
flap1.visible = this.flap1Visibility = false;
} else {
flap1.visible = this.flap1Visibility = true;
}
}
flap1.visible = this.flap1Visibility;
The code you pasted has two issues:
flap1.visible
setting to the inside of the Click
listener. You want it outside of the listener so that it gets called on every frameRevised code:
import gs.*;
import gs.easing.*;
TweenMax.to(movieclip1, 2, {scaleX:4, scaleY:4, ease:Elastic.easeOut});
function move_to_top(e:MouseEvent):void {
if (flap1.visible) {
flap1.visible = this.flap1Visibility = false;
} else {
flap1.visible = this.flap1Visibility = true;
}
animateClip()
}
flap1.visible = this.flap1Visibility;
animateClip()
function animateClip():void {
if (flap1.visible == false) {
this.setChildIndex(movieclip1, this.numChildren - 1);
flap1.addEventListener(MouseEvent.CLICK, move_to_top);
}
}
Upvotes: 1