Sound doesn't play from an mc when loaded using moviecliploader | Member | | Join Date: Jan 2008
Posts: 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 -
_global.my_beep_sound = new Sound();
-
my_beep_sound.attachSound("beep_sound");
-
trace("Sound file loaded"+my_beep_sound);
-
player.swf -
-
// create an empty movie clip
-
this.createEmptyMovieClip("my_mc", this.getNextHighestDepth());
-
-
// Create Movie clip loader for sound
-
var my_mcl:MovieClipLoader = new MovieClipLoader();
-
var mclListener:Object = new Object();
-
-
// Setup events for preloader
-
mclListener.onLoadStart = function(target_mc:MovieClip):Void {
-
};
-
mclListener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number):Void {
-
};
-
mclListener.onLoadComplete = function(target_mc:MovieClip):Void {
-
};
-
mclListener.onLoadInit = function(target_mc:MovieClip):Void {
-
trace("init");
-
trace(my_beep_sound);
-
my_beep_sound.start(0,999);
-
};
-
my_mcl.addListener(mclListener);
-
-
// Load sound
-
my_mcl.loadClip("sound.swf",my_mc);
-
The trace output is: -
Sound file loaded: [object Object]
-
init
-
[object Object]
-
Thanks,
Chromis
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: Sound doesn't play from an mc when loaded using moviecliploader
When you create your new sound object, try doing: | | Member | | Join Date: Jan 2008
Posts: 113
| | | 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
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | 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
| | | 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?
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | 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
| | | 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.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: Sound doesn't play from an mc when loaded using moviecliploader Quote:
Originally Posted by chromis 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
| | | re: Sound doesn't play from an mc when loaded using moviecliploader
Haha fair play, I'll remember that in the future.
Chromis
|  | Similar Flash / Actionscript bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,223 network members.
|