type writer effect with sound
hi everyone, i was trying to figure out how to link sound to each character while appearing on screen using the type writer effect here is my as.
var s:Sound = new Sound ();
s.attachSound("mySound");
s.setVolume(100);
s.start()
var tf_reference = _root.tf_instance; // a reference to your text field
// typewriter effect
var runTypeWriter = function(tf, text) {
if(text.lenght < 1) return; // nothing to type
var chr_per_second = 100; // characters per second
// now the effect
tf.text = ''; // cleaning the text field
var c_int;
var c_char = 0;
var add_chr = function() {
tf.text += text.charAt(c_char);
c_char++;
if(c_char >= text.length) clearInterval(c_int); // effect done
}
c_int = setInterval(add_chr, Math.round(1000/chr_per_second));
}
// load the text
var c_load = new LoadVars();
c_load.onData = function(raw) {
if(raw == undefined) {
// could not load the file, printing error instead
runTypeWriter(tf_reference, 'File could not be loaded!');
} else {
runTypeWriter(tf_reference, raw);
}
}
c_load.load('pastor.txt');
the problem is that the sound just plays at start and not throughout the effect. any help would be appriciated
|