473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

113 100+
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
8 2820
Markus
6,050 Expert 4TB
When you create your new sound object, try doing:

Expand|Select|Wrap|Line Numbers
  1. new Sound(this)
  2.  
Mar 2 '09 #2
chromis
113 100+
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
6,050 Expert 4TB
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
chromis
113 100+
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
6,050 Expert 4TB
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
chromis
113 100+
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
6,050 Expert 4TB
@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
chromis
113 100+
Haha fair play, I'll remember that in the future.

Chromis
Mar 2 '09 #9

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

Similar topics

5
by: minchu | last post by:
Hello, I want an image and sound(any format) to load and play simultaneously in my HTML or the sound should play only after the image is loaded. Is this possible?. Pls let me know how. ...
22
by: The Road To Utopia | last post by:
Here's one for the trolls...a common jibe from them is setting up audio/video hardware under linux. Ok, true story: at work today, someone asked me if I could tell him why his XP Home would play...
1
by: Marco Krechting | last post by:
Hi All, I have a database with the timer function set to warn the user that arecord is due to expire. Is there a Win API that I can use so a loud warning will go off. Not this simpel beep in...
4
by: Robert Gravereaux | last post by:
I'm putting together a C# .Net forms project on win2k. The application requires some sort of horn sound. I've never implemented any audio in .Net, so I'm not sure how best to accomplish this. ...
3
by: illmagination | last post by:
Hi, I recently received a task to have a .wav file play only once when home page is 1st loaded and only play again when the user re-visits the page by opening a new browser. I am using...
6
by: laredotornado | last post by:
Hi, Is there a cross-browser way to play short (< 25K) sound files without spawning new windows or embedding any visual controls on the page? I would like to click a button and hear my short...
26
by: Jake Barnes | last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching for "how to play a sound with Javascript". I'm somewhat suprised that the majority of entries are from the 1990s, and there are...
8
by: raylopez99 | last post by:
I have the latest version of Visual Studio 2008 Professional, which allows you to create resource files (this is the .resx file, no?), unlike the Express version, which does not. I am trying to...
1
anfetienne
by: anfetienne | last post by:
i have this code below that i made....it loads vars from txt file splits it then puts it into an array....once in an array it the brings the pics in from the array to create thumbnails and a larger...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.