?
Solved

Actionscript 2 Play Pause sound from media controller

Posted on 2010-08-23
17
Medium Priority
?
849 Views
Last Modified: 2013-11-11
I'm trying to get my media controller to play and pause but everytime I click the button it play another instance of the sound. Please help complete noob!

My code is as follows:

on (click) {
      kirupaSound = new Sound(this);
      kirupaSound.attachSound("sample.mp3");
      kirupaSound.start(0, 99);
      kirupaSound.test();
0
Comment
Question by:Lico_w
  • 9
  • 8
17 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 33507953
that's because you are creating new Sound each time.

declare your sound on the timeline

var kirupaSound:Sound = new Sound();
attach code
start .. blah

what's kirupaSound.test() ??????

then in your onClick()

call kirupaSound.stop() // start();
0
 

Author Comment

by:Lico_w
ID: 33508725
Okay so ive got the following in my timeline:

var kirupaSound:Sound = new Sound();
kirupaSound.attachSound("sample.mp3");

and this in my mediacontroller:

on (click) {
      kirupaSound.start(0, 99);}

Do I not need to put the timeline stuff in a function? If so how do I do it? I tried the above as is and it did nothing.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 33508923
can you upload your file?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Lico_w
ID: 33508981
File attached as requested.
SoundPlayer1.fla
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 33509088
ok when they click the component it starts playing, but when it clicks the pause button in the component its supposed to pause and then close again. is that correct?
i'm not familiar with this component but you're going to need a bit more work than that.
you're going to have to check if the sound is currently playing, if it is, then don't trigger the start action again because the click on component is overriding the click of the pause button inside the component.

is there documentation for this component?
0
 

Author Comment

by:Lico_w
ID: 33509139
No, when I try to run it as a flash movie it does nothing! The sound doesn't play when I click play or pause.

I know that I will need an If statement etc. to check if sound is playing or not and act accordingly to pause or play further down the line but it won't play in the first place, thats my problem....

Does the sound play when you export the movie from flash then???
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 33509228
okay just change the thing to on (release) instead of click
then do your if statements.

0
 

Author Comment

by:Lico_w
ID: 33509270
No good I'm afraid still does nothing. If it's easier I can change to Actionscript 3 would there be a solution in that?
0
 
LVL 39

Accepted Solution

by:
blue-genie earned 1000 total points
ID: 33509521
sorry i'm multi-tasking too much

on (release)
{
      _root.kirupaSound.start();
}
0
 

Author Comment

by:Lico_w
ID: 33510075
Thanks a lot I've now got it working ;-D

Only issue is the controller shows as paused when its playing and as streaming when it's paused. Is there an easy fix for this? My code is below:

Timeline Code:-
var isPlaying:String = "notPlaying";
var kirupaSound:Sound = new Sound();
kirupaSound.attachSound("sample.mp3");

Controller Code:
on (click)
{
      if (isPlaying <> null)
      {
            _root.kirupaSound.start(0, 99);      
            isPlaying = null;
            
      }
      else
      {
            _root.kirupaSound.stop();
            isPlaying = "notPlaying";
      }
}

Also any pointers on how to configure the volume button much appreciated.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 33510138
as i said i need the documentation on that component, i don't know it and there doesn't seem to be any parameters to it.
0
 

Author Comment

by:Lico_w
ID: 33510564
Okay is there a simple way of doing this with the standard buttons i.e. I can have a play and stop button, but how do I make the play button change to pause once clicked - I guess I would need to navigate to a new keyframe with the pause button in, but how is that done?
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 33510609
make your buttons into movieclips NOT buttons.

create a variable such as

var isPlaying:Boolean = false;
once that hit start, set the variable to true.

if (isPlaying) {
movieclip.gotoFrameThatIsPause;
} else{
moveclip.goSomwhereElse;
}
0
 

Author Comment

by:Lico_w
ID: 33511066
that sounds a bit tricky for a complete noob like me!!!

Anyway I re-looked at my component and docs on Adobe.com and have resolved the issues, thanks for your help with this one!!!

;-)
0
 

Author Closing Comment

by:Lico_w
ID: 33565719
Only partial completion, I still need more info on the media controller component, so any additional help would be appreciated.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 33566571
as I said I'm not familiar with that particular component, and then you decided that you werent' going to use it anymore.
0
 

Author Comment

by:Lico_w
ID: 33575166
my comment wasn't meant to offend you!

I put it in the hope someone who DID know about that particular component would see it and pick it up....

I did look at changing the component but as I stated right at the start I am a noob to this and I didn't really understand what I needed to do with the alternative, it was to brief.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question