Jump to content
Search Community

Animating Nav with TimelineMax Sounds

barredow test
Moderator Tag

Recommended Posts

I have a flash site designed with several frames with unique sounds. I also have a very simple animating button that when clicked turns off the sounds on that frame and takes you back to the homepage.

 

it's current code for that one navigation mc is

		    mcName.addEventListener(MouseEvent.CLICK, goHome);
function goHome(event:MouseEvent):void {

gotoAndPlay("home");
	soundFish1.soundPaused  = !soundFish1.soundPaused;
	   tlFish.gotoAndStop(0)
}

 

*note= soundfish1 refers to a repeating sound and tlFish refers to a timeline with sound

 

Now I want to create a more advanced animated navigation that goes to more than just one frame. The problem is that I can't seem to be able to target the TimelineMax sounds from within the nested movieclip navigation.

 

Can anyone help? I've included a simple version of what I'm talking about. The buttons work but I need the sounds from frame 2 to stop when you click back to the homepage. Note= I will have other sounds playing on the homepage but didn't include in the file.

Link to comment
Share on other sites

Hi,

 

the main problem with your file is that you have code in different frames and also inside of movieclips.

 

the meat of your sound loading and playing code is on Frame 2 of the timeline, but your nav button code is inside the nav movieclip which is on frame 1 of the main timeline.

there is no way to reference objects that are created on Frame 2 of the timeline from code that is on frame 1 of your movie.

 

so if you have code inside your nav that says

 

 soundFish1.gotoSoundTime(0, true);
tlFish.play()
//etd

 

it isn't going to work because when the code inside your nav compiles, those objects don't get created until frame 2 and you will get errors.

 

---

 

The reason Adobe and others recommend to put as much code on Frame 1 or in an external document class is to avoid these types of problems.

 

Since you haven't gone too far it isn't too late to restructure things. You can put all your code for your nav buttons, loading of sounds and playing of sounds on Frame1. if you so choose you can wait til the user gets to frame 2 to trigger the loading of the sounds or the playback of TimelineLites (that were created on frame 1).

 

for instance, the code you have inside your nav :

 

frame2.addEventListener(MouseEvent.CLICK, goframe2);
function goframe2(event:MouseEvent):void {
MovieClip(root).gotoAndPlay(2);
}

home.addEventListener(MouseEvent.CLICK, goHome);
function goHome(event:MouseEvent):void {
MovieClip(root).gotoAndPlay(1);
}

 

can be placed on Frame 1 (be sure to name the clip that holds the buttons "nav"

 

nav.frame2.addEventListener(MouseEvent.CLICK, goframe2);
function goframe2(event:MouseEvent):void {
gotoAndPlay(2);
}

nav.home.addEventListener(MouseEvent.CLICK, goHome);
function goHome(event:MouseEvent):void {
gotoAndPlay(1);
}

 

make sense?

 

unfortunately I don't have time to update all the other code for you.

Link to comment
Share on other sites

ok, i made a few changes to your file. couldn't resist.

 

all the sounds load on frame 1 and the timeline is built.

 

all actions are applied to the buttons on frame 1.

 

once everything load sthe movie advances to frame 2 which is now the "home" page.

frame 3 is now the "sound" page.

 

the buttons take you to frame 2 or 3. we never want to go back to frame 1 because then all the variables, loaders, sounds etc will be overwritten (bad).

 

this still isn't the best approach but it is a little better.

 

see the attachment

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...