Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Actionscript 2 Play Pause sound from media controller

Posted on 2010-08-23
17
768 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
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 set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

808 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