0

Original Edit I am wanting to know the best method for a making a movieClip fade way on the stage. I can guess how to do it in as2 (that's what I was taught in) but I'm unsure how to to develop my code below. As a guess I would assume to attach it to an enterFrame event.

Basically, over the course of 5 seconds if the user hasn't interacted with the balloon, it fades to nothing using alpha.

Any pointers or suggestions? I'm new to AS3. (please ignore the CLICK)

reset_balloon.addEventListener(MouseEvent.CLICK, fadeBalloon);
 function fadeBalloon(event:MouseEvent):void 
 { 
    reset_balloon.alpha = .2; 
 } 

Secondary Edit -----

//---- 
//Resetter btn ---------------------
//------------------------------------------

reset_btn.addEventListener(MouseEvent.CLICK, startover);

 function startover(event:MouseEvent):void
  {
   //gotoAndPlay(2);
   reset_balloon.visible = true;
  }

  //---- 
Object(root).reset_balloon.thereseter_btn.addEventListener(MouseEvent.CLICK, truestartover);

  function truestartover(event:MouseEvent):void
  {
     gotoAndPlay(2);
   //reset_balloon.visible = false;
  }


  TweenLite.delayedCall(5, handleTimeUp)

   function handleTimeUp():void
   {
    TweenLite.to(reset_balloon, 2, {alpha:0});
   }

   reset_balloon.addEventListener(MouseEvent.CLICK, fadeBalloon);

    function fadeBalloon(event:MouseEvent):void 
     { 
     //reset_balloon.alpha = .5; 
  TweenLite.killDelayedCallsTo(handleTimeUp);
  TweenLite.to(reset_balloon, 2, {alpha:0.4});
    }
user3082874
  • 61
  • 2
  • 11

1 Answers1

0

If you don't mind using Tweens, I'd recommend TweenLite for this one.

//Add function called in 5 secs
TweenLite.delayedCall(5, handleTimeUp)

private function handleTimeUp():void
{
    TweenLite.to(reset_balloon, 2, {alpha:0});
}

And if for some reason you want to kill pending delay call (for example on mouse click);

reset_balloon.addEventListener(MouseEvent.CLICK, fadeBalloon);
private function fadeBalloon(event:MouseEvent):void
{
    TweenLite.killDelayedCallsTo(handleTimeUp);
}
3vilguy
  • 981
  • 1
  • 7
  • 20
  • instead of using "TweenLite.delayedCall()" to delay the tween triggering, you could also replace it with a regular Timer object. Then every time the user interacts with the balloon, you can reset the timer to start counting from 0 again (I'm not familiar enough with TweenLite to know if it offers this 'reset' method). – mitim Feb 04 '14 at 11:20
  • You can `killDelayedCallsTo` and add `delayedCall` once again. – 3vilguy Feb 04 '14 at 11:24
  • Hello, both sound interesting although I am more familiar with tweening. What is Tween light? What does it serve? – user3082874 Feb 05 '14 at 14:41
  • Check out web page: [TweenLite – A Lightweight, FAST Tweening Engine](http://www.greensock.com/tweenlite/) – 3vilguy Feb 05 '14 at 14:50
  • Hello, yeah it looks great! I just downloaded it and added it to my project. I'm having an issue now tho, when I let it fade it won't come back. Any ideas or suggestions? TweenLite.delayedCall(5, handleTimeUp) function handleTimeUp():void { TweenLite.to(reset_balloon, 2, {alpha:0}); } reset_balloon.addEventListener(MouseEvent.CLICK, fadeBalloon); function fadeBalloon(event:MouseEvent):void { //reset_balloon.alpha = .5; TweenLite.killDelayedCallsTo(handleTimeUp); TweenLite.to(reset_balloon, 2, {alpha:0.4}); } – user3082874 Feb 05 '14 at 17:23
  • Can you EDIT your main question and move this code in there? Because in comment formatting is rubbish. – 3vilguy Feb 05 '14 at 17:31
  • Hello 3vilguy - sorry about that. Changes have been made above. – user3082874 Mar 07 '14 at 12:31