Loading XML for use in the same function?

Hello there,

This is sort of to do with my earlier post here:

What I ended up doing was having the class function [main();] call loadXML(); which would then call processXML(); when it was finished. Here is what I started using:


public function main() {
            loadXML(_targetURL);
        }
        private function loadXML(_targetURL) {
            getXMLLoad = new xmlLoad(_targetURL);
            getXMLLoad.addEventListener(Event.COMPLETE, onComplete);
        }
        private function onComplete(evt:Event) {
            xmlData = getXMLLoad.getXML();
            processXML();
        }

Now as I have started to restructure my code, as it wasn’t very OOP-like, I would like to call loadXML(); without having to move to a new function, thus keeping my code in one function.

Can this be done?

what you would want to do is call loadXML() or obj.loadXML()(and make the function internal by removing the private) where obj is an instance of the class that loadXML is inside.

you should parse your xml into a data class and then access the data through your “global” data class variable.