0

I have a function called processXML on the timeline (yes, I know now...) which does what I want it to do e.g. it loads XML, is passed into several arrays and manipulates things on screen. Cool

I have another function, a TIMER, from which I'd like to call the function above e.g. processXML.call()

(I want it to load fresh data every 10-20 seconds)

But no luck. I'm new to AS3 but can't seem to get it working.

Am I missing something fundamental?

2 Answers 2

1

just processXML() should work. This, obviously, if both functions are at the same level on the timeline.

Or simply when your first frame is loaded you can do

var xmlInterval:Number=-1;
var msGap:Number=20000; //Sets the millisecond gap to 20000 milliseconds between calls
xmlInterval=setInterval(processXML, msGap); //calls processXML every msGap milliseconds
//And to stop calling processXML when you don't need it,
clearInterval(xmlInterval);
Sign up to request clarification or add additional context in comments.

4 Comments

@user1203605, can you post your processXML code here? Or at least just the first (function signature) line?
var myXML:XML; var myLoader:URLLoader = new URLLoader(); myLoader.load(new URLRequest("myText.xml")); myLoader.addEventListener(Event.COMPLETE, processXML); function processXML(e:Event):void { myXML = new XML(e.target.data);
It sees processXML is being called by the load event of an xml loader. So instead of doing setInterval(processXML, msGap); you need to use setInterval(loadXML, msGap); where loadXML will call loader.load(URLRequest);
Yep, discovered that. Thanks for your help!
0

Are you trying to do something like this?:

import flash.utils.Timer;
import flash.events.TimerEvent;

var aTimer:Timer = new Timer(10000); // 10 seconds
aTimer.addEventListener(TimerEvent.TIMER, timeToDoSomethingAgain);

function timeToDoSomethingAgain(evt:TimerEvent):void {
    trace("timeToDoSomethingAgain");
    processXML(); //Call your function, DO NOT SAY processXML.call() as this is incorrect
}

function processXML():void {
    //Stuff in your function
}

Also, are you wanting to load the xml from file every 10-20 seconds or just reference an already loaded xml object?

2 Comments

Yes, I'm trying to do something like the above. But Flash doesn't like me calling processXML(); Everything else works similar to the example you gave.
Waiting to self answer - being a nube 'n all. Anyway... Ok, my bad. Couldn't see the wood for the trees. Easy answer, really. Just needed to put myLoader.load(new URLRequest("myText.xml")); in the timer function. processXML fires any time it loads... Doh!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.