By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,665 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,665 IT Pros & Developers. It's quick & easy.

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

100+
P: 113
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
Mar 2 '09 #1
Share this Question
Share on Google+
8 Replies


Markus
Expert 5K+
P: 6,050
When you create your new sound object, try doing:

Expand|Select|Wrap|Line Numbers
  1. new Sound(this)
  2.  
Mar 2 '09 #2

100+
P: 113
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
Mar 2 '09 #3

Markus
Expert 5K+
P: 6,050
No that doesn't work. Here's a discussion on the problem that seems to explain it pretty well (and offers a solution too).
Mar 2 '09 #4

100+
P: 113
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?
Mar 2 '09 #5

Markus
Expert 5K+
P: 6,050
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.
Mar 2 '09 #6

100+
P: 113
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.
Mar 2 '09 #7

Markus
Expert 5K+
P: 6,050
@chromis
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.
Mar 2 '09 #8

100+
P: 113
Haha fair play, I'll remember that in the future.

Chromis
Mar 2 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.