Solved

Actionscript 2 Play Pause sound from media controller

Posted on 2010-08-23
17
752 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
Comment Utility
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
Comment Utility
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
Comment Utility
can you upload your file?
0
 

Author Comment

by:Lico_w
Comment Utility
File attached as requested.
SoundPlayer1.fla
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
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
Comment Utility
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
Comment Utility
okay just change the thing to on (release) instead of click
then do your if statements.

0
 

Author Comment

by:Lico_w
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 39

Accepted Solution

by:
blue-genie earned 500 total points
Comment Utility
sorry i'm multi-tasking too much

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

Author Comment

by:Lico_w
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now