attachSound() Won’t Play in Loaded Movie- Another Flash Bug!
Categories: Flash
I came across this bug awhile ago. Lets say you had the following code in a SWF:
noise = new Sound(); noise.attachSound("asound"); noise.start();
It worked perfectly, the sound with the linkage ID in my library names “asound” played and everything was great.
Now try loading that SWF info another SWF, the sound will not play. I searched the net and found this nice little comment here:
“For what it is worth, I had the same issue, and found a solution to this.
When declaring the “new Sound”, you have to specify a target movie clip. For example:
new_sound = new Sound(this)”
Ah-Ha! Specifying this in the Sound object’s constructor magically makes it work. This isn’t anywhere in MM’s docs. Thanks MM for wasting 30 more minutes of my time!
Ok, so it doesn’t tell you in exactly those words, but it sort of does tell you.
“Constructor; creates a new Sound object for a specified movie clip. If you do not specify a target instance, the Sound object controls all of the sounds in the movie.”
So basically if your Sound() object does not have a target, it becomes global, which is a no no for attachments unless you feel like getting into Shared Libraries.
Though honestly, their description is very vague, and they should make note of it at least in their attachSound() description. I hate when help documents assume you don’t need help.
So yes… THANKS MM FOR WASTING 30 MOTE MINUTES OF HIS TIME!