Я использую следующий код для проверки обновлений в базе данных mysql с использованием flash as3 (actionscript 3.0).
Код проверит базу данных с помощью PHP на моем сервере и отобразит детали в приложении Flash.
У меня проблема в том, что я пытаюсь запустить этот код каждые 8 секунд, но когда я запускаю код и я trace(urlRequest);
Я получаю 100 следов менее чем за 20 секунд!
Я думал, давая setInterval(checkDataBase, 8000);
разберусь с этой проблемой и буду запускать код каждые 8 секунд, но мне не повезло с этим!
Может кто-нибудь, пожалуйста, посоветовать по этому вопросу?
Это мой код:
addEventListener(Event.ENTER_FRAME,checkForNewOrder);
function checkForNewOrder (e:Event):void
{
checkDataBase();
}
/*
function we use to send the form
*/
function checkDataBase ():void
{
/*
we use the URLVariables class to store our php variables
*/
var phpVars:URLVariables = new URLVariables();
phpVars.result_textL = result_textL.text;
/*
we use the URLRequest method to get the address of our php file and attach the php vars.
*/
var urlRequest:URLRequest = new URLRequest("http://mywebsite.com/checkOrder.php");
trace(urlRequest);
/*
the POST method is used here so we can use php's $_POST function in order to recieve our php variables.
*/
urlRequest.method = URLRequestMethod.POST;
/*
this attaches our php variables to the url request
*/
urlRequest.data = phpVars;
/*
we use the URLLoader class to send the request URLVariables to the php file
*/
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
/*
runs the function once the php file has spoken to flash
*/
urlLoader.addEventListener(Event.COMPLETE, showResult);
/*
we send the request to the php file
*/
urlLoader.load(urlRequest);
}
setInterval(checkDataBase, 8000);
/*
function to show result
*/
function showResult (e:Event):void
{
orderDetails.text = "" + e.target.data.result_message;
if(orderDetails.text != "")
{
rejectBtn.y = 380.20;
}
}
addEventListener(Event.ENTER_FRAME,checkForNewOrder);
Это приводит к тому, что ваша функция вызывается с установленной вами частотой кадров, поэтому вы можете делать это 30 раз в секунду.
setIntervall добавит дополнительные вызовы к функции. Это не отменяет ввод кадра.
Избавьтесь от регистра ввода кадров, и вы должны быть в порядке.
Других решений пока нет …