Skip to main content
Participating Frequently
January 27, 2013
Answered

Actionscript 3 coding to return to home page 10 secs after sound file stops

  • January 27, 2013
  • 1 reply
  • 660 views

Hi..

I am having some problems with my Flash Project.

At the moment the whole thing works but I now need it to do something I have never done before.

Basically, the user will select a page and the project will then run, via actionscript 3.0 coding, a sound file and display the appropriate page within the timeline.

I have a back button that once tapped will return to home page.

I now need it to return to home page 10 secs after the sound file has stopped as well as keep the function of the back button.

What do I do?

I can provide the coding I am using if required.

I am currently using Flash Pro CS6 on a Win 7 Pro PC.

Thank you for your help

Michael

This topic has been closed for replies.
Correct answer Ned Murphy

If you need to time something happening you have a couple of choices of timer elements to choose from. 

The least complicated would likely be to use the setTimeout() function and have it call the same function that the button uses.  You just need to assign the function's event argument to null (as in:  function buttonFunctionName(evt:MouseEvent=null) ).

Another option is to use the Timer class.

Both of these options are documented in the help files if you need to find how to use them.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
January 27, 2013

If you need to time something happening you have a couple of choices of timer elements to choose from. 

The least complicated would likely be to use the setTimeout() function and have it call the same function that the button uses.  You just need to assign the function's event argument to null (as in:  function buttonFunctionName(evt:MouseEvent=null) ).

Another option is to use the Timer class.

Both of these options are documented in the help files if you need to find how to use them.

Participating Frequently
February 3, 2013

Thank you Ned for your help, however as I do not really understand how the settimeout function works, it has now made me more confused.

I think I have nutted out what I am trying to say.

Essentially my project is like a web page if you like.

I have six individual pages which all display a picture and play a sound file.

What I would like to do is after each page is selected it will play a sound file, I then want it to wait 10 secs and then go back to a

home page (which will be frame 1) or if they are impatient there is a back button that directs you back to frame 1.

I have included the code used by the back button to manually get back to frame 1 either whilst the sound file is playing or after it has finished

back_btn.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToGoToAndStopAtFrame_1);

  function fl_ClickToGoToAndStopAtFrame_1(event:MouseEvent):void

{

    gotoAndStop(1);

}

/* Click to Stop All Sounds

Clicking on the symbol instance stops all sounds currently playing.

*/

back_btn.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToStopAllSounds);

function fl_ClickToStopAllSounds(event:MouseEvent):void

{

    SoundMixer.stopAll();

}

I just want it to return to home page automatically once the sound file is finished and there is nil input from the touch screen. (This will simulate someone walking away midway and leaving it with 2nd  web page showing.)

I hope this makes sense.

Thank you

Ned Murphy
Legend
February 3, 2013

Show the code you use to initiate the sound.  That is where you need to initiate the timing activity.

You do not need two functions for handling the same event and it will probably be less confusing for you to understand and keep track of if you don't do what you show...

back_btn.addEventListener(MouseEvent.CLICK, fl_BackBtnClick);

function fl_BackBtnClick(event:MouseEvent):void

{

    gotoAndStop(1);

    SoundMixer.stopAll();

}