Copy link to clipboard
Copied
Hi all
I posted a question that related to this problem a few weeks ago in the general forum, but I'm now almost certain that this is an actionscript issue.
I have a flash interface that I've built for a client that is a schematic of a factory and it displays various bits of data. It's extremely simple and involves calling a dynamically generated variable string from a php file and displaying the values. This is the actionscript that I'm using:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function dataLoader():void {
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, loading);
loader.load(new URLRequest("http://www.mysite.com/myscript.php"));
function loading (event:Event):void {
flow_1.text = loader.data.flow_1;
flow_2.text = loader.data.flow_2;
flow_3.text = loader.data.flow_3;
}
}
dataLoader();
setInterval(dataLoader,30000);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
As you can see it's very simple. It runs the dataLoader() function as it loads and then uses setInterval to reload the data at intervals (this is necessary for the functionality of the interface).
The problem I'm getting is this:
It's infuriating because it's hard to debug. If I Teamviewer in to the client's machine and try to debug it and it starts working I may think that I've solved the problem, but each time I've done this it's just been a coincidence and the script has decided to work for an hour on that computer!!!
Any help with a solution or possible debugging strategy would be extremely welcome.
TIA
Chris
Copy link to clipboard
Copied
I'd change this:
loader.load(new URLRequest("http://www.mysite.com/myscript.php"));
To this:
loader.load(new URLRequest("http://www.mysite.com/myscript.php?r=" + int(Math.random()*999999)));
That would avoid cache while loading data from myscript.php.
Copy link to clipboard
Copied
Thanks for the tip Sinious, I'll include it in my script.
Am I right in thinking that a caching issue wouldn't be causing no data to display though? I'm guessing if there's a caching issue it would be old data that just wouldn't refresh. Is that right?
Thanks,
Chris
Copy link to clipboard
Copied
You would just receive cache for that address, yes. It has caused me troubles in the past I've entirely gone around by just random seeding each request with bogus random information. The real bugger is when proxies get involved and sometimes don't feed the request back properly from its own cache. That simple tactic solves that issue as well, unless unfortunately you randomly generate the same seed number out of a million .
Copy link to clipboard
Copied
I assume you also have an error handling part, but haven't shown it? Is that doing anything?
Some other things to think about might be instead of having the function go every 30 seconds have it go 30 second after the last complete (or sooner if there is an error) or something like that? I often worry with things like this that you end up setting more than one interval and the start overlapping.
Finally I might suggest looking into using something like LoaderMax from GreenSock. They seem to have it together with regards to avoiding caching and other types of problems that might affect various player/browser combinations.
Copy link to clipboard
Copied
This script could help to isolate your problem: compile it and let it run on the problematic users computer, with the myText.txt file in the same folder.
You might adjust it to your needs, and put a real response from your php-Script in it.
var counter:int = 0;
var _title:String = "";
var _body:String = "";
var _myURL:String = "";
function loadText():void
{
var myTextLoader:URLLoader = new URLLoader();
myTextLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void
{
counter++;
_title = e.target.data.myTitle;
_body = e.target.data.myBody;
_myURL = e.target.data.myURL;
myTextField.appendText(counter +":"+ _title + _body + _myURL+ "\n");
}
myTextLoader.load(new URLRequest("myText.txt"));
}
setInterval(loadText,3000);
//myText.txt. Dummy-content ->
//myTitle=This is &myBody=a URLLOaderTest&myURL= www.flashforums.com
Copy link to clipboard
Copied
Thanks for the suggestions guys. I'm working through them now and I'll report back in the next few days.
Thanks,
Chris
Find more inspiration, events, and resources on the new Adobe Community
Explore Now