Connecting Tech Pros Worldwide Help | Site Map

Sound doesn't play from an mc when loaded using moviecliploader

Member
 
Join Date: Jan 2008
Posts: 113
#1: Mar 2 '09
Hi,

I've been struggling to get sounds to work with attachSound when the sounds are stored in a swf loaded into another swf. I came across a post on a forum which supposedly explains how to to do it, however i tryed what it suggested and it doesn't work. (link)

I then tryed to use the MovieClipLoader class so that once the swf was loaded the sound would be played. What is strange though is that when the swf has loaded i can return a valid reference to the sound object, but cannot play it. This is all local, so it should play. I'm very confused.

Here is my code:
sound.swf - beep_sound.wav file is in the library with linkage identifier beep_sound
Expand|Select|Wrap|Line Numbers
  1. _global.my_beep_sound = new Sound();
  2. my_beep_sound.attachSound("beep_sound");
  3. trace("Sound file loaded"+my_beep_sound);
  4.  
player.swf
Expand|Select|Wrap|Line Numbers
  1.  
  2. // create an empty movie clip
  3. this.createEmptyMovieClip("my_mc", this.getNextHighestDepth());
  4.  
  5. // Create Movie clip loader for sound
  6. var my_mcl:MovieClipLoader = new MovieClipLoader();
  7. var mclListener:Object = new Object();
  8.  
  9. // Setup events for preloader
  10. mclListener.onLoadStart = function(target_mc:MovieClip):Void {
  11. };
  12. mclListener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number):Void {
  13. };
  14. mclListener.onLoadComplete = function(target_mc:MovieClip):Void {
  15. };
  16. mclListener.onLoadInit = function(target_mc:MovieClip):Void {
  17.     trace("init");
  18.     trace(my_beep_sound);
  19.         my_beep_sound.start(0,999);
  20. };        
  21. my_mcl.addListener(mclListener);
  22.  
  23. // Load sound
  24. my_mcl.loadClip("sound.swf",my_mc);
  25.  
The trace output is:
Expand|Select|Wrap|Line Numbers
  1. Sound file loaded: [object Object]
  2. init
  3. [object Object]
  4.  
Thanks,

Chromis
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#2: Mar 2 '09

re: Sound doesn't play from an mc when loaded using moviecliploader


When you create your new sound object, try doing:

Expand|Select|Wrap|Line Numbers
  1. new Sound(this)
  2.  
Member
 
Join Date: Jan 2008
Posts: 113
#3: Mar 2 '09

re: Sound doesn't play from an mc when loaded using moviecliploader


Hi Marcus,

Can't tell you how pleased I am you've sorted that out for me, thanks! Was really stuck on that one. So does that change the timeline for the sound to the the containing mc? What is it otherwise?

Thanks again,

Chromis
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#4: Mar 2 '09

re: Sound doesn't play from an mc when loaded using moviecliploader


No that doesn't work. Here's a discussion on the problem that seems to explain it pretty well (and offers a solution too).
Member
 
Join Date: Jan 2008
Posts: 113
#5: Mar 2 '09

re: Sound doesn't play from an mc when loaded using moviecliploader


I did have a look at that whilst i was researching the issue, it's not really the way i wanted to go about it though as on the actual project that has the issue I've got a moviecliploader which loads the main swf. Your solution above worked a treat though. What's strange is I would assume the sound constructor to take the movieclip it's in as a target as default. Instead it seems to be the current root right?
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#6: Mar 2 '09

re: Sound doesn't play from an mc when loaded using moviecliploader


Oops, I hadn't seen your reply before I made my second post. Sorry about that.

Yes, I would've thought the object would default to the movie clip / button it's in - of course, your's isn't in a movie clip or button.

Time to do some research :D

Also, don't double post your question :P

Glad I could help,
Markus.
Member
 
Join Date: Jan 2008
Posts: 113
#7: Mar 2 '09

re: Sound doesn't play from an mc when loaded using moviecliploader


Sorry about the double post, although technically it's not the same question, more of a development from the previous one ;)

Thanks again for you help.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#8: Mar 2 '09

re: Sound doesn't play from an mc when loaded using moviecliploader


Quote:

Originally Posted by chromis View Post

Sorry about the double post, although technically it's not the same question, more of a development from the previous one ;)

Thanks again for you help.

Sure, but while it's an extension of this question, it still largely relates to this thread. So, no need to create a new thread, although I won't hold it against you.

See ya around,

Markus.
Member
 
Join Date: Jan 2008
Posts: 113
#9: Mar 2 '09

re: Sound doesn't play from an mc when loaded using moviecliploader


Haha fair play, I'll remember that in the future.

Chromis
Reply