Best Practices in using Flash for CALL activities
The purpose of this document is to share my experience in using Flash to develop modular CALL activities. Much of my skills have been built from the ground up, through trial and error. I've built up a somewhat disorganized set of conventions from that experience. I'm writing this document in the hopes of sharing my experience, and generating dialog among those using Flash for CALL.
General sound parameters:
Record sound in 16 bits, at least 22 kHz (44 kHz is better)
Export sound using the speech format, at 22kHz
Playing on demand via script
Yo have to import and link audio clips before you can play on demand via scripting. When you name the link, use the same name as the movieclip that contains the button to play the sound.
For example, if you have a movieclip called "mcButter," then name the link to the audio file "sndButter." The advantage to this is keeping the sound script more generic. In the script, you can strip off the "mc" and add the "snd" part of the name.
The button script might look something like this:
onClipEvent(mouseUp){
if(hitTest(_root._xmouse, _root._ymouse, false)){
_parent.playSound(this._name);
//calls the function "playSound," with the parameter "mcButter"
}
}The script to play the sound can then reside in the timeline of the parent movieclip, and look like this:
function playSound(myName){
theSound = "snd" + myName.substr(2, myName.length);
//strip off the "mc" part of mcButter, and add "snd" to the beginning
mySound = new Sound();
mySound.attachSound(theSound);
mySound.start():
}
Including Unicode-formatted text in Flash
Flash for Windows is not Unicode-aware, although the Macintosh version seems to handle non-roman text better than the Windows version. To include text in the non-roman character set, you have three options:
1. Using #include
2. Loading external text files using loadVars or loadVariables
3. Pulling text in from a database using loadVars or loadVariables
If you are using external files, you must put the following line at the top of your file:
//!-- UTF8
That will indicate to Flash that the file contains Unicode text.
The #include method integrates the contents of an external file into the Shockwave file during the process of creating the Shockwave file. The contents of the external file becomes part of the Actionscript. That means that the external file must comply with Actionscript format.
For example, if you want to put some Chinese text into a dynamic text field on the stage called "myText," you can put this line of script in the timeline of the first frame:
#include "myFile.as"
The contents of myFile.as would be like this:
//!-- UTF8
myText.text = "中華民國萬歲";
After the Shockwave file is created, the external file is no longer needed.
Loading external text files allows you to pull the contents of the external file at runtime.
varname1 = 我的文字&varname2=中華民國萬歲
onClipEvent(data) {
//text manipulation routines here. For
example, to place the value of varname1 into a text field called "myText"
_root.myText.text = varname1
//You can split the text into an array,
then put the 3rd word of the sentence into the text field
myArray = varname1.split("");
_root.myText.text = myArray[2];
//Whatever
}
loadVariables("externalText.txt", "_root.mc1");
Note: In case you're wondering why I don't use the LoadVars object for external text files, I have found that it does not "reset." After running successfully once, the function will not re-check the file a second time. In other words, if you load the text file once, then change the text file, and try to re-load it, the function will think it has already successfully loaded the text file, and will not bother to do it again. The LoadVariables command is stateless, and so I chose to use it instead.
The loadVars method allows you to pull text in from a database, using a server-side scripting language such as PHP. Here's a sample function that accesses the server. You can put the function anywhere - in the timeline, a movieclip, or a button.
function getClips(){
myLV = new LoadVars();
myLV.userID = _global.myID; // Send parameters to the server-side script this way
myLV.onLoad = function(){
// Deal with the text just like you would any other text. Here's an example
// "myText" is from the server script.
myArray = myLV.myText.split("|");
for (x=0; x<myArray.length-1; x++){
tempArray = myArray[x].split("~");
_root.myClips.myClipList.addItem(tempArray[0],tempArray[1]);
}
}
myLV.sendAndLoad("http://complete.path.to/server/scriptFile.php", myLV, "GET");
}
Kinds of interactivity:
It's more elegant to communicate with the server through functions, rather than looping through frames in the timeline.