Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Playing a mp3 when a movie clip loads

New Here ,
Nov 29, 2013 Nov 29, 2013

I am using Adobe Flash Professional CS6

What I am trying to do is play a mp3 file that I have in my library when the clip loads and stop playing it when the a new clip is selected from the menu I created.  On the button that loads the movie clip (Instance name: Slideshow), I have the following code:

on (release){

    gotoAndPlay(120);

}

onClipEvent (load){

    mySong = new Sound();

    mySong.attachSound("MastersThisHall");

    mySong.start(0,50);

}

onClipEvent (unload) {

    mySong.stop();

}

- I went to the properties of the MastersThisHall.mp3 file in my library,

- Selected the "ActionScript", tab,

- Checked the box that says "Export for ActionScript",

- Unchecked the "Export in frame 1" check box, and

- Added MastersThisHall in the "Identifier" field.

The sound is NOT playing when I when the "Slideshow" button is pressed.

Ideas?

TOPICS
ActionScript
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 30, 2013 Nov 30, 2013

remove all sound from your objects (movieclips and buttons).  assign your buttons and movieclips, that execute code, instance names (in the properties panel).

for example, name your "Mute" button (mute_btn), your "Resume Sound" button (unmute_btn), your "Pause" button (pause_btn) and create a play button (play_btn).

also, assign your 6 buttons that direct your timeline to different frames instance names (eg, mc0_btn, mc1_btn, mc2_btn,.., mc5_btn) and put those frames in an array:

SlideshowMusic = n

...
Translate
Community Expert ,
Nov 29, 2013 Nov 29, 2013

attach this code to your main timeline:

mySong = new Sound(this);

   mySong.attachSound("MastersThisHall");

    mySong.start(0,50);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 29, 2013 Nov 29, 2013

When I do that I get a compile error that says "Clip events are permitted only for movie clip instance".


What I did was this: On frame 120 (the Slideshow instance), I attached this code to the movie clip object.

------------------------------------------

onClipEvent (load){

    mySong.attachSound("MastersThisHall");

    mySong.setVolume(vol);

    mySong.start(0,50);

}

onClipEvent (unload) {

    mySong.stop();

}

------------------------------------------

And I put this code in frame 1

------------------------------------------

var vol: Number;

mySong = new Sound(this);

------------------------------------------

if I do this, I do not get any errors, but it still does not work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2013 Nov 29, 2013

follow the suggestion i made in message 1.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 29, 2013 Nov 29, 2013

Like I said before, I did that. I placed that code in frame 1.

This does not work at all. This code implies that is is going to play that file on frame 0 of the flash file.

Nothing happens.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2013 Nov 29, 2013

the suggestion in message 1 won't trigger that error. you have some other code triggering it.

this might be a good time to clean up all your coding by removing all code from movieclips and buttons.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 29, 2013 Nov 29, 2013

Wierd! It just started playing.

I curently only have the following code in my .fla file.

---------------------FRAME 1---------------------

SlideshowMusic = new Sound(this);

SlideshowMusic.attachSound("MastersThisHall");

stop();

------------------------------------------------------------------------

---------------------FRAME 120 (On the Movie Clip Object)---------------------

onClipEvent (load) {

    SlideshowMusic.start(0,1);

    SlideshowMusic.setVolume(10);

}

onClipEvent (unload) {

    SlideshowMusic.stop();

}

------------------------------------------------------------------------

I am not getting ANY compile errors at all.

However, the mySound.setVolume(10); line is not lowering the volume, and the onClipEvent (unload) function is not working (it is supposed to stop playing the file when I select a different movie clip to play.

Ideas?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2013 Nov 29, 2013

on frame 120, if that's where you want to decrease the sound's volume, delete all code attached to your movieclip object) and attach to the main timeline:

SlideshowMusic.setVolume(10);

if you want to stop the sound, when something (eg, stopSound_mc) is clicked, use:

stopSound_mc.onRelease=function(){

SlideshowMusic.stop();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 29, 2013 Nov 29, 2013

Thank you for all of this; it is very helpful.

I have series of 6 buttons I created, each of them load a different movie clip. I need to have the music from the slideshow NOT continue to play when a new movie clip is selected.

I have the following code.

Frame 1:

--------------------------------------------------------------------

SlideshowMusic = new Sound(this);

SlideshowMusic.attachSound("MastersThisHall");

stop();

--------------------------------------------------------------------

Frame 120 (attached to the Slideshow movie clip object):

--------------------------------------------------------------------

onClipEvent (load) {

    SlideshowMusic.play();

}

--------------------------------------------------------------------

The "Mute" Button:

--------------------------------------------------------------------

on (release) {

    SlideshowMusic.setVolume(0);

}

--------------------------------------------------------------------

The "Resume Sound" Button:

--------------------------------------------------------------------

on (release) {

     SlideshowMusic.setVolume(100);

}

--------------------------------------------------------------------

And the "Pause" Button:

--------------------------------------------------------------------

on (release)

{

  if (SlideshowMusic.position < SlideshowMusic.duration)

  {

    SlideshowMusic.start(SlideshowMusic.position / 1000);

  }

}

--------------------------------------------------------------------

It is loading and working perfectly. However, I have two more questions:

1. How do I make the the sound automatically stop when a new movie clip is played?

2. How do I change the "pause" symbol to the "play" symbol when the "Pause" button is pressed?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2013 Nov 30, 2013

remove all sound from your objects (movieclips and buttons).  assign your buttons and movieclips, that execute code, instance names (in the properties panel).

for example, name your "Mute" button (mute_btn), your "Resume Sound" button (unmute_btn), your "Pause" button (pause_btn) and create a play button (play_btn).

also, assign your 6 buttons that direct your timeline to different frames instance names (eg, mc0_btn, mc1_btn, mc2_btn,.., mc5_btn) and put those frames in an array:

SlideshowMusic = new Sound(this);

SlideshowMusic.attachSound("MastersThisHall");

stop();

play_btn._visible=false;

var gotoA:Array=[120,220,100,50,300,72];

for(var i:Number=0;i<gotoA.length;i++){

this["mc"+i+"_btn"].ivar=i;

this["mc"+i+"_btn".onRelease=function(){  //<-this encodes all 6 buttons

this.gotoAndStop(gotoA[this.ivar]);

pause_btn.onRelease();

}

}

mute_btn.onRelease=function(){

SlideshowMusic.setVolume(0);

}

unmute_btn.onRelease=function{

SlideshowMusic.setVolume(100);

}

pause_btn.onRelease=function(){

SlideshowMusic.stop();

this._visible=false;

play_btn._visible=true;

}

play_btn.onRelease=function(){

if (SlideshowMusic.position < SlideshowMusic.duration)

  {

    SlideshowMusic.start(SlideshowMusic.position / 1000);

  }

this._visible=false;

pause_btn._visible=true;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 30, 2013 Nov 30, 2013

Wow! That is wonderful. Will this stop the sound when the new movie clip is run?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2013 Nov 30, 2013

yes, it pauses the sound when any of the 6 buttons is clicked.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 30, 2013 Nov 30, 2013

And what happens when the next movie clip has music running in the background? How do I make this work for that as well?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2013 Nov 30, 2013

when you play a movieclip does that mean you goto a frame where that movieclip is located?

which sounds (ie, what's their linkage id) play when which movieclips (ie, if the answer to the above is yes, which frames correspond to which linkage ids) play?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 01, 2013 Dec 01, 2013

Nevermind, it is all working flawlessly now. Thank you very much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2013 Dec 01, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines