Flex 3: synchronous loading of xml file

My question is very simple: is there a way in flex3 to load the xml file synchronously?

I know how to load asynchronously using a load event. It may or may not be useful. I just want to read the file, analyze it, do what I have to do with it, and continue executing the code.

I have a component that uses an xml file to store some configuration options. I need to read a file when an object is initialized. However, with the event model, I cannot control when the file is uploaded, so I have to write code to “wait” for the code to load. Is it just funny, or is it me? I need a code:

var foo:Foo = new Foo(); //This constructor should read the xml and initialize the object.
foo.doSomething(); //When I call this method the xml must be already handled.

I can handle the XML file in the event, and it works fine, but the event is after the method doSomething.

I hope I explained it myself. I think it should be very easy, but it drives me crazy. I do not want to write code to wait for an event if it is really necessary. I feel that all this should be only one line of code!

+3
source share
5 answers

Unable to download synchronously, Flash is made for the web, and you can never be sure how long a call will take. Air is different in that it loads from the file system, and there does not exist the same delay.

The purest solution would be to listen to the load inside Foo and call doSomething () from the inside, so your "external" class should not bother at all.

foo.doSomething() , . Foo , .

dispatchEvent(new Event(Event.COMPLETE, true));

, :

foo.addEventListener(Event.COMPLETE, handleFooComplete);

:

private function handleFooComplete(e:Event):void{
    foo.doSomething();
}

, Event.COMPLETE . .

+1

, "" .

() do() , new() do() calld ()

pseudosyntax:

beforeInitialisation()
  disableDoSomething()
  new()...
  loader.addEvent(AFTERLOAD, afterLoad)


afterLoad()
  enableDoSomething()


someMethod()
  doSomething()
+1

, , - . dirkgently Peter Miehle , .

, . , - . , , , .

, , - xml . , , xml, , . , , , " " Foo.

?

+1

, , , .

Create a custom event that you dispatch inside a function that processes resultEvent

Have the object you want to do something, I think in this case it was foo to listen to this custom event, which then will call doSomething ().

+1
source

Invoke foo.doSomething();from within the event handler for the XML loading event (for example, EVENT.Completeor something, depending on how you are loading the file). This is the recommended method.

0
source

Source: https://habr.com/ru/post/1704642/


All Articles