PDA

View Full Version : Hey guys sound issue



nathan99
October 28th, 2005, 03:18 AM
Ok ladies and getns
How would i attach in a sound from an externally loaded sound. I had a method which i think will work. BUT i dont know if this is a bug with macromedia flash but i have lthis code


var my_sound:Sound = new Sound();
my_sound.attachSound("song", 99);
my_sound.start();


but it wont play. any ideas, and yes, i put the sound in the swf w/out loading externally to test this. and i think there lies my issue, because the exact same code works perfect in another swf

claudio
October 28th, 2005, 06:51 AM
It dosnt work because you didnt specify a target whenyou defined the sound instance.

var my_sound:Sound = new Sound(this);
my_sound.attachSound("song", 99);
my_sound.start();

nathan99
October 28th, 2005, 10:10 AM
still dont work

claudio
October 28th, 2005, 10:59 AM
Perhaps i misunderstanding something here.
You are trying to attach some sound file from a child swf from the parent swf?

nathan99
October 28th, 2005, 11:01 AM
its in the movie library

claudio
October 28th, 2005, 11:04 AM
Can you explain the scenario?
Where is the sound? In the main swf or in the external swf? and where are you trying to attach the sound?

nathan99
October 28th, 2005, 11:17 AM
its in the main swf, and on layer 5, frame 5.

kritikal
October 28th, 2005, 11:29 AM
var my_sound:Sound = new Sound();
my_sound.attachSound("song");
my_sound.start(0,99);

;)

Barn
October 28th, 2005, 11:39 AM
It dosnt work because you didnt specify a target whenyou defined the sound instance.
The target is only necessary if volume control is required. It is not necessary for simple starting and stopping.

Nathan, you say this is an externally loaded sound, but it looks to me like it was imported, since you're using attachSound. Which did you do? Load the sound to a sound object (with the requisite onLoad event handler) or did you import it and give it a linkage name?

kritikal
October 28th, 2005, 11:43 AM
The target is only necessary if volume control is required. It is not necessary for simple starting and stopping.

Nathan, you say this is an externally loaded sound, but it looks to me like it was imported, since you're using attachSound. Which did you do? Load the sound to a sound object (with the requisite onLoad event handler) or did you import it and give it a linkage name?

he is being a bit confusing, he also said that it's in the librairy

its in the movie library

claudio
October 28th, 2005, 11:44 AM
Im almost positive that if you dont specify a target and load the swf into another movie, the sound will not play.

Barn
October 28th, 2005, 12:42 PM
Im almost positive that if you dont specify a target and load the swf into another movie, the sound will not play.
I didn't see where Nathan said he was doing that. Maybe I'm just missing it but it looks to me like everything is local in a single movie.

claudio
October 28th, 2005, 12:49 PM
I didn't see where Nathan said he was doing that. Maybe I'm just missing it but it looks to me like everything is local in a single movie.
Well, maybe im missing it too.

stringy
October 28th, 2005, 04:15 PM
Maybe i`ll miss as well
use the code Claudio gave but don`t forget to give the sound a linkage identifier-song

nathan99
October 28th, 2005, 09:51 PM
OK guys. heres the go:
i had a sound, tried loading it with an external swf, didnt work,:
then, i imported it into my movie, and DID NOT try to load it in externally;
gove it a linkage name;
then i used bot mine and claudios code, both to no avail

get it now, sorry bout the confusion

TheCanadian
October 28th, 2005, 10:34 PM
Make sure the linkage id is correct. Other than that, I'm afraid that there is not much else we can do since that code should work. Maybe attach an FLA or something :)?

nathan99
October 28th, 2005, 11:18 PM
OK i had to just copy all the stuff i had in that other swf and move it into another
but nw i want to be able to load it in externally with a preloader any ideas?

TheCanadian
October 29th, 2005, 12:09 AM
this.createTextField("message_txt", this.getNextHighestDepth(), 10, 10, 300, 22);
this.createTextField("status_txt", this.getNextHighestDepth(), 10, 50, 300, 40);
status_txt.autoSize = true;
status_txt.multiline = true;
status_txt.border = false;
var my_sound:Sound = new Sound();
my_sound.onLoad = function(success:Boolean) {
if (success) {
this.start();
message_txt.text = "Finished loading";
}
};
my_sound.onSoundComplete = function() {
message_txt.text = "Clearing interval";
clearInterval(my_interval);
};
my_sound.loadSound("mySound.mp3", false);
var my_interval:Number;
my_interval = setInterval(checkProgress, 100, my_sound);
function checkProgress(the_sound:Sound):Void {
var pct:Number = Math.round((the_sound.getBytesLoaded() / the_sound.getBytesTotal()) * 100);
var pos:Number = Math.round((the_sound.position / the_sound.duration) * 100);
status_txt.text = the_sound.getBytesLoaded() + " of " + the_sound.getBytesTotal() + " bytes (" + pct + "%)" + newline;
status_txt.text += the_sound.position + " of " + the_sound.duration + " milliseconds (" + pos + "%)" + newline;
}

:thumb: