Flash to RDB
Code sample
This Actionscript extract shows how chord data queries are handled.
When the host movie needs data, it calls the request function. Data is cached locally, to prevent repeat searches.
cache = new Array(); // local chord cache
match = new Array(); // search matches
function request(root, type)
{
if (isCached(root, type))
{
_root.searchResult = collectFromCache();
_root.displayResult();
}
else
{
fetchData(root, type);
}
}
function isCached(root, type)
{
delete match;
match = new Array();
var i;
for (i = 0; i < cache.length; i++)
{
if (cache[i][0] == root && cache[i][1] == type)
{
match.push(i);
}
}
if (match.length)
return true;
else
return false;
}
function collectFromCache()
{
if (!match.length)
return null;
chordsFound = new Array();
var row;
for (row = 0; row < match.length; row++)
{
chordsFound.push(cache[match[row]]);
}
return chordsFound;
}
function fetchData(root, type)
{
trace("in fetchData()...");
loadVariables("http://www.chordbook.com/search.php?root="
+root+"&type="+type, "", "POST");
}