Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xmlconnector data loaded event MX2004 Pro?

Status
Not open for further replies.

jcaulder

Programmer
Apr 22, 2002
241
US
Anybody know a way to determine when an xmlconnector has completed the load of its data from the server?

I am using PHP to build the xml. Problem is processing occurs in Flash before the results are back from the server. I have been unable to find any examples of doing this using the built in XML UI Component.

TIA!

J
 
You would do it by adding an event listener to the Data set. (assuming you are using the dataset component as well)

Code:
//Trigger XML Connection
this.ConnectorInstanceName.trigger();

dataListener = new Object();
dataListener.afterLoaded = function(){
	gotoAndPlay(2);
        //replace with whatever you executed after the data loads.
}
_root.dataSetInstanceName.addEventListener("afterLoaded", dataListener);
stop();

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Thanks for the reply!

I had tried that, among several other things. And it does work I have now found.

What I found to be my problem was that a component bound to the dataset or xmlconnector is not necessarily loaded just because the dataset.afterLoaded fires. I was checking the value of a textinput in the 'afterLoaded' function. However, this value kept coming out 'undefined' or either still set to a previous value. I even tried putting a delay in to give the textinput time to load from the dataset but this still gave inconsistent results.

The only solution I've found is to reference the dataset.currentItem.fieldName value directly instead of relying on the textinput.

It seems there is no way to really know when the UI components bound to the dataset have loaded. Have you had this problem?

I even considered using the onChange of the textinput but that only fires through user interaction, not through programmatic changes.

I've worked around it but I sure would like to know the correct way to know when the components are loaded as well as the dataset.

Any ideas?

Thanks!

J
 
What I do is insert that code into the first frame of the movie. I execute the trigger and then apply the listener to the dataset. The function on AfterLoad is gotoAndPlay(2);

I then set my dataset items on frame 3 of the time line.

I have not experienced any timing problems using this method. You would want to reference the dataset item directly anyway. Then you would use it to set your input box value. (if I understand you correctly)

For example:
Code:
//Trigger XML Connection
this.ConnectorInstanceName.trigger();

dataListener = new Object();
dataListener.afterLoaded = function(){
    _root.dataSetInstanceName.first();
    myInputBox.text = _root.dataSetInstanceName.currentItem.textValue;
    //gotoAndPlay(2);
        //replace with whatever you executed after the data loads.
}
_root.dataSetInstanceName.addEventListener("afterLoaded", dataListener);
stop();

Hope that helps you. Sounds like you already hav a work around but you really shouldn't need one.

Wow JT that almost looked like you knew what you were doing!
 
I am triggering my connector based upon a user clicking a button so I can't do it in frame1 like you have. The user can click the button multiple times to query different data. It sounds like the way you've broken it into different frames gives enough delay to prevent the problem.

It also sounds like you're doing all the databinding programmtically whereas I set all my databinding visually using the develop environment and rely on it to handle it for me.

Guess I'll continue with my work around and hope it doesn't cause me any more problems. I have too much developed to change the system now. Maybe I'll try programmatic databinding on the next project.

Thanks again!
 
Actually I used the component databinding. I am progammatically changing which record I am viewing, but the bindings are all handled within the component inspector.

You should still be able to accomplish the same thing with a button.

Code:
buttonName.onclick = function(){
   this.ConnectorInstanceName.trigger();
}

// same listener code as above

I can see where you would have trouble if your button is clicked more than once though. I guess if you have something that works then it's all good! :)

Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top