user1203605
user1203605

Reputation: 83

AS3 Call function from Another function

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?

Upvotes: 0

Views: 2417

Answers (2)

pho
pho

Reputation: 25490

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);

Upvotes: 1

ToddBFisher
ToddBFisher

Reputation: 11610

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?

Upvotes: 0

Related Questions