4.3 the WDDX output
Second flash frame, the graphic:

We have two combo box (selected from the component panel): protoList and protoName, a textfield named info and one named fn_text, then a scrollbar that controls the fn_text.
- protoList: list of categories
- protoName: list of functions of a category
- info: function info
- fn_text: full function text
And now let's analyze the AS present in the second frame:
// -----------------------
// function that populates
// the combo box with the
// list of all categories
// present in the wddxObj
// -----------------------
populateCombo = function()
{
// set the first item of the combo
protoList.addItem("Pick category");
// for every object in the wddxObj
for(var a in wddxObj)
{
// add its value to the combo
protoList.addItem(a)
}
// sort the combo
protoList.sortItemsBy('labels','ASC');
}
populateCombo();
protoName._alpha = 30;
protoName.setEnabled(false);
This first function take the wddxObj and populate the combo box (protoList) with the list of the categories, and then set the combo protoName disabled.
Let's continue with the second function:
// -------------------
// this function check
// which cateogry is selected
// and displays all functions
// related to it.
populateName = function()
{
var theValue = protoList.getValue();
// clear the textfields
info.text = '';
fn_text.text = '';
// if is not selected the first combo item
if(theValue != "Pick category")
{
// set itself enabled
protoName.setEnabled(true);
protoName._alpha = 100;
// remove all values
protoName.removeAll();
// set the first item
protoName.addItem("Pick function");
// and for each value present in the
// array title inside wddxObj
for(var a in wddxObj[theValue]['title'])
{
protoName.addItem(wddxObj[theValue]['title'][a],a);
}
} else {
protoName.removeAll();
protoName.setEnabled(false);
protoName._alpha = 30;
}
}
This function is called when you select an item from the protoList combo and it populate the protName combo with the list of function present in the category you choose.
And the last two functions of our movie:
// --------------------
// insert into the info
// textfield all the information
// about the function selected
function viewInfo()
{
if(protoName.getSelectedItem().label == 'Pick function') return;
info.text = '';
// it gets the value from the
// combos
var cat_id = protoList.getValue();
var fn_id = protoName.getValue();
info.text = "Title: " + protoName.getSelectedItem().label + newline;
info.text += "Author: " + (wddxObj[cat_id]['email'][fn_id]) + newline;
info.text += "Date: " + (wddxObj[cat_id]['data'][fn_id]) + newline;
info.text += "Flash Version: " + (wddxObj[cat_id]['version'][fn_id]) + newline;
info.text += "id: " + (wddxObj[cat_id]['id'][fn_id]) + newline;
// now call this function
// passing as argument the value
// of the protoName combo
get_text(wddxObj[cat_id]['id'][fn_id]);
}
// -----------------------
// load variables from php
// -----------------------
function get_text(id)
{
// pass to php the value
// id passed from the
// function caller
var g = new LoadVars();
fn_text.text = 'Loading....';
g.load('wddx_1.php?id=' + id);
g.onLoad = function()
{
// once page is loaded
// show result in the
// scrollable textfield
fn_text.text = this.fn
};
}
The populateName function is called from the combo list protoName (see the picture above) since it has as changeHandler the name of this function.
this function get the value from the two combos and uses them to define the text into the two textfields present in the stage.
In the info textfield will place the informations present in the wddxObj in this way:
info.text = "Title: " + protoName.getSelectedItem().label + newline;
while to set the full text of the function it will call the last function get_text passing to it as argument the value of variable id.
get_text function then creates a loadVars object and call the wddx.php page passing it the value of the function id with http_get_var method. PHP will return the full text of that function and the LoadVars object will put it into the fn_text textfield
