Jump to content
Search Community

Tweenmax mc rollover only working every other time

barredow test
Moderator Tag

Recommended Posts

I created a basic invisible button that plays a movie clip when it's rolled over. However, for some reason when I test the movie it only works on every other rollover. Can anyone help me figure out why?

 

Here's the buttons code (it plays a random movie):

 

xperson1_btn.addEventListener(MouseEvent.ROLL_OVER, playRandomMovieClip1);
function playRandomMovieClip1(event:MouseEvent):void {
if (randomNumber==1) {
	fishermanClip1.gotoAndPlay(2);
	blondeClip1.gotoAndStop(1);

} else {
	fishermanClip2.gotoAndPlay(2);
	blondeClip2.gotoAndStop(1);
}
}

 

 

Here's my movieclip code for the 2nd frame, the first frame just has a stop action in it:

 

 

 

stop();

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import com.greensock.OverwriteManager;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.*
import flash.events.Event
import flash.media.Sound;
import flash.media.SoundChannel;


OverwriteManager.init(1)
var clips:Array = [ hereFishy_mc ];

TweenMax.allTo(clips, 0, {autoAlpha:1});

var sound1:MP3Loader = new MP3Loader("audio/HereFishyRough.mp3", {autoPlay:false});

var queue:LoaderMax = new LoaderMax({onComplete:init});

queue.append(sound1);

queue.load();

var tl:TimelineMax = new TimelineMax({paused:true})


tl.addCallback(playSound1, tl.duration);
tl.append(TweenLite.to(hereFishy_mc, 1.5, {autoAlpha:1}));
tl.append(TweenLite.to(hereFishy_mc, 1.5, {autoAlpha:0}));

function init(e:LoaderEvent):void
{
 trace("soundsComplete"); 
 tl.play();
}

function playSound1():void{
  sound1.gotoSoundTime(0, true);
  }

Link to comment
Share on other sites

it appears the playback of your animation is tied into the loading of your sound.

 

does "sound complete" trace every time you rollover?

 

the way you have things set up there are many possible points of failure that you need to test:

 

1: doe the clip go to frame 2?

2: does the timeline get created properly

3: does the sound load properly?

4: does the timeline play?

 

 

 

if it is at all within your skill set I would urge you to try to come up with a way that you can load your sound once and create your timeline once. then when ever you do a roll over you just have to tell the timelinemax to restart().

Link to comment
Share on other sites

  • 2 weeks later...

Ok I did that. And it works fine on one frame. But I'm having a problem when I try to create another background sound in another frame on the timeline using the same method.

 

I keep getting:

 

 

ArgumentError: Error #2068: Invalid sound.

at flash.media::Sound/play()

at com.greensock.loading::MP3Loader/_playSound()

at com.greensock.loading::MP3Loader/set soundPaused()

at BackgroundButtonsLoopsDiffFramesFINAL_fla::MainTimeline/toggles2()

soundsComplete

 

 

I've included a zipped up file. Would you mind taking a look at it?

Link to comment
Share on other sites

i had a very difficult time making sense of what was happening and what was supposed to happen in your code.

 

I managed to narrow down exactly when the error is occurring.

 

it seems your toggles2 function is being called as soon as the user clicks on the bottom button on frame1.

at that point in time sound5 doesn't yet exist or hasn't been loaded.

 

stage.addEventListener(MouseEvent.CLICK, toggles2);

// function to toggle soundpaused state

//add these 2 traces to your toggles2 and you will see that this is happening most likely before you intend it to happen

function toggles2(event:MouseEvent):void
{
trace(sound5);
trace("the error happens now");
       sound5.soundPaused  = !sound5.soundPaused;

}

 

you might want to make sure that the stage click eventlistener isn't added until the queue2 finishes loading.

also I noticed that the onComplete for queue2 is set to init but but you have an init2 function on that same frame.

so just realize that when queue2 finishes loading it is calling the same init function queue is calling back on frame 1.

maybe that will help.

Link to comment
Share on other sites

Sorry for the confusion. I redid the file so it hopefully is easier to see what I'm trying to accomplish.

 

I'm trying to make a file with 2 frames. Each frame has a unique background audio loop and also a button that on rollover plays a sound effect and reveals a solid colored shape.

 

Each background audio loop should only play on its frame.

 

I changed the name function name like you suggested so the queue2 would not be calling the same function queue was in frame 1. That worked.

 

So now I can switch back between the frames and the loops start and stop fine as long as I only click on the button to move to either frame 1 or frame 2. However, if I click anywhere else on the frame the sound stops. I'd like for it to just stop when I left the frame.

 

Is there a better way to create somewhat of an event listener so that the loops will only stop if you exit their frame?

 

 

I've attached the new file . Appreciate your help.

Link to comment
Share on other sites

i think i got it closer to working.

 

this new file had the same problem(s) as the other one.

the invalid sound error was still there.

 

i changed a couple of things.

 

whenever you did

 

tl.addCallBack(playSomeSound, tl.duration)

 

i changed it to

 

tl.addCallBack(playSomeSound, .01)

 

you were adding multiple callbacks at a time of 0 and your timelines didn't have any duration. it is difficult for a timeline to play if it doesn't have a duration.

 

also you were adding MouseEvent.CLICK listeners to buttons and the stage and it was really messing things up.

 

I consolidated your functions like so:

 

 btn3.addEventListener(MouseEvent.CLICK, goto2ndFrame);

function goto2ndFrame(event:MouseEvent):void {

gotoAndPlay("frame2");
 sound3.soundPaused  = !sound3.soundPaused;
}

 

I really don't see any use for using TimelineMax as you have as you aren't really sequencing anything.

You would be better off just telling each sound to play/pause when you interact with each button instead of adding callbacks to a timeline that call functions that tell sounds to play.

 

Also the whole approach of loading multiple sounds and configuring multiple buttons on multiple frames and then going back and forth between those frames makes it VERY difficult to make sense of the code and update it. As a general rule you should try to put as much code as possible on Frame 1 and load your sounds and create your tweens, functions and listeners once in one place instead of doing it multiple times.

I understand where you are coming from, it is something you will adapt to, but the sooner you start experimenting with such an approach the better off you will be. Unless you have elaborate keyframed animation, there are very few times that you really need more than 1 frame in a fla.

 

insteading "going to frame2" you could call a function like

 

showFrame2(){

//add code to stop all the "frame 1" sounds

//make all the buttons and graphics invisible

//start the "frame2" sounds

//make the "frame2" buttons and stuff visible

}

 

it is very easy to hide each frame's visual elements if you put them all in the same movie clip.

 

just some ideas.

Link to comment
Share on other sites

  • 4 weeks later...

Carl,

 

That worked pefectly. Much better. I definitely agree with you on setting everything up on one frame but I could never figure out quite how to do it with multiple sounds, loader frames and animations.

 

Here's what I currently have: 2 frames with UI Loaders loading in external images and content from an external xml file, 6 more frames with unique green sock animations that have sounds throughout and some utilize different background loops.

 

My only problem right now is if I test the movie and go to one of the frames and leave before the animation completes the sounds in that animation will continue on another frame. So I will get sound from the wrong frame if I leave too quickly.

 

What would you suggest? I'm guessing I need to put the animations on each frame into separate movieclips then put them on one frame and control with code? I just don't know how to do that.

 

Hope that makes sense. I'll be glad to create another example if it doesn't. Again thanks for your help.

Link to comment
Share on other sites

I don't understand the following:

 

6 more frames with unique green sock animations[b] that have sounds throughout[/b]

 

how are you triggering your sound? with TimelineLite? onComplete callback functions? DelayedCalls?

 

take a look at killTweensOf()

http://www.greensock.com/as/docs/tween/ ... lTweensOf()

 

whenever you go to another frame, try to kill or the tweens that are triggering your sounds or pause the timelines that are playing.

Link to comment
Share on other sites

Thanks for your help Carl.

 

To further explain the problem I created several scenes each on there own frame with their own timeline. Some of these scenes had a repeating audio in a loop and others had audio in the timeline that was still playing if the user went to another frame and new timeline in the swf.

 

What I found to work was to pause the background sound and also the timeline it was in. For some reason just stopping the timeline didn't stop the repeating sound. Below is an a button that I made that takes you out of the current frame to a home page. soundFish1 was the name of the repeating sound and tlFish was the name of the timeline Max animation.

 

There might be a better way to do this but I got it to work by:

 

goHomeButton.addEventListener(MouseEvent.CLICK, goHomeTest);

function goHomeTest(event:MouseEvent):void {

 

gotoAndPlay(1);

soundFish1.soundPaused = !soundFish1.soundPaused;

tlFish.gotoAndStop(0)

 

}

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...