The combo Box:
We keep all of the available translation modes in a separate text file from which we load into Flash and populate the combo box with. First we need to create a text file with the necessary data. How this text file is formatted is the most important aspect of populating components with external data sources. So here's a look:
&mode0=en_fr&desc0=English to French& &mode1=en_zh&desc1=English to Chinese& &mode2=en_de&desc2=English to German& &mode3=en_it&desc3=English to Italian& &numModes=4&
Ok what the data contains is not as important as how it's formatted. In the download we have a text file with all of the modes contained in it. In this example we are just using 4 possible modes so it doesn't take up to much space. Notice how the numbers work, after each mode and desc variable their is an increasing incremental number, ie 0,1,2,3. The mode in this case is a string that for example looks like 'en_fr' indicating English to French, that is all that is really needed. We added the description (desc) variable as a way to visually display the short hand.
Next we have to load this text file (called Modes.txt in the download) - into the movie. The ActionScript for that will look like the following:
// Create a New LoadVars Object
myModes = new LoadVars();
// This Tells the Flash movie What function to invoke when the Load Vars Is complete.
myModes.onLoad = addModes;
// Find the Text File - Load it - after which the function addModes is invoked.
myModes.load("Modes.txt");
We are using the LoadVars Object in this case to load the text file. This is useful because we can use the .onLoad function associated with the Load Vars object to wait for the data to load - and then invoke a function when it's done (addModes). That function will populate the combo box with the data from the Text file - and looks like this:
function addModes() {
// Loops through the number of listings in the text file and sets them up as nodes.
for (i=0; icomboBox.addItem(desc, Modes);
}
} The comments in the script above should cover about everything. Basically we loop through each record in the text file and add an item to the combo Box for each row in the text file. By creating a data provider for each we can assign as much data to each individual combo box item as needed. This function is found in the 'Functions' layer of the FLA that comes with the download. Some more examples and downloads for this type of thing can be found here: flash-db.com/Components/
So with the combo Box set up and all of the component styles and formats set
- we have something that looks like:
So now it's onto the interesting stuff.
| » Level Advanced |
|
Added: 2002-08-19 Rating: 7 Votes: 10 |
| » Author |
| Jeffrey Hill is a freelance web developer from Boulder, Colorado. He specializes in creating and developing dynamic database driven Flash content, applications, and content management systems. Specialty's include SQL, PHP, Perl, XML, web services, and Flash clients for web services. |
| » Download |
| Download the files used in this tutorial. |
| Download (251 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


Comments
There are no comments yet. Be the first to comment!