PDA

View Full Version : Loading Variables from PHP


devnill
10-25-2006, 05:47 AM
I am creating an app in flash that will monitor the bandwidth my computer consumes and alerts the user when they exceed a certain point.

On the homepage of my college, there is page a that will display how much bandwidth was used sofar into the day, and I have created a php script to output a plaintext number that is the number of megabytes used.

The problem that i am having has to do with flash loading the value. Ive tried the loadVariables() function, but i am having no luck.

the following is my PHP, it uses a regular expression to find the number on the url, and outputs it without any formatting.

<?php
$site=file('http://wa1.alfredstate.edu/bandwidth/default.php');
$unsorted=implode(',',$site);
preg_match("/<td>(.*?) Megabytes<\/td>/",$unsorted, $matches);
echo $matches[1];
?>


How can i have flash load the value the php outputs?
Thanks,
Dan Singer

peptobismol
10-25-2006, 06:52 AM
echo 'myVar=' . $matches[1];

then in flash do a loadVariables or use LoadVars to get the value of 'myVar'

Flash Gordon
10-25-2006, 07:16 AM
echo '&myVar=' . $matches[1];

devnill
10-25-2006, 05:07 PM
Ok, it loads fine the first time, but the php script seems to only run once. Im pretty sure this is because flash is caching the file. Is there anyway to force the file to reload?

heres the actionscript:

var cv = 0;
var speed = 2500;
loadVariablesNum("settings.conf", 0);
var connectInterval = setInterval(configLoaded, 100);
stop();
function configLoaded() {
if (file == undefined) {
trace("attempting to load configuration");
} else {
clearInterval(connectInterval);
_root.serverAddy = _root.server+_root.file;
start();
}
}
function checkParamsLoaded() {
if (usage == undefined) {
trace("attempting to connect to "+_root.serverAddy);
loadVariablesNum(_root.serverAddy, 0);
} else {
dispUsage = usage;
loadVariablesNum(_root.serverAddy, 0);
cv++;
trace(cv);
if (cv == 2) {
trace("speed shift started");
clearInterval(_root.param_interval);
_root.speed = 60000;
_root.param_interval = setInterval(checkParamsLoaded, _root.speed);
}
}
}
function start() {
_root.param_interval = setInterval(checkParamsLoaded, _root.speed);
}


and the php:

<?php
$site=file('http://wa1.alfredstate.edu/bandwidth/default.php');
$unsorted=implode(',',$site);
preg_match("/<td>(.*?) Megabytes<\/td>/",$unsorted, $matches);
echo 'usage=' . $matches[1];
?>

peptobismol
10-25-2006, 09:28 PM
you use an & when you want to pass multiple variables like
myVar=123&poppy=332&

and yes it does cache so do
loadVariablesNum("settings.conf?cache="+ random(5000), 0);