
Chapter 3 48
6 Remember to connect the shared object to the NetConnection object.
// Connect to the shared object
rec_so.connect(client_nc);
7
Create an event handler for when the user selects Record, which publishes the new recordings
and updates the shared object.
function doRecord() {
if (ListItem.text == undefined || ListItem.text == "") {
Status_msg.text="Please enter a title.";
} else if (Record_btn.getLabel() == "Record") {
Status_msg.text="Recording...";
// Stop any currently playing stream
if (Play_btn.getLabel() == "Stop")
doPlay();
// Don’t allow the user to play while recording
Play_btn.setEnabled(false);
// Create output stream
out_ns = new NetStream(client_nc);
// Start publishing the audio output as a recorded stream
out_ns.attachAudio(Microphone.get());
// Publish the stream
out_ns.publish(ListItem.text, "record");
// This allows the entering of single-word list items
_root.rec_so.data[ListItem.text] = ListItem.text;
_root.rec_so.flush();
// Change the button label
Record_btn.setLabel("Stop");
8
If the button label is Stop, close the output stream and allow the user to play from the list.
} else if (Record_btn.getLabel() == "Stop") {
// Close output stream
out_ns.close();
// Now that you’re finished recording, allow the user to play
Play_btn.setEnabled(true);
// Change the button label
Record_btn.setLabel("Record");
// Clear the ListItem.text
ListItem.text="";
Status_msg.text="...";
}
}
Comentários a estes Manuais