> Hi Coders
> 
> I have problem with the following code. I cannot return the 
> value but i can trace inside the onload. I am mentioning the 
> dummyXML. Anyone can help would be appricated.
> 
> function mloader(file, toobject) {
>  encLoad = new LoadVars();
>  encLoad.onLoad = function(success) {
>   xmldata = encLoad.data;
>   decdata = RC4.decrypt(xmldata, "mykey");
>   dummyXML = new XML();
>   dummyXML.ignoreWhite = true;
>   dummyXML.parseXML(decdata);
>   return dummyXML;
>  };
>  encLoad.load(file);
> }

You have a kind of scope problem. Your mloader function doesn't return
anything, only the embedded onLoad function (and this actually doesn't
return anything either, because it doesn't have any calling function to
return it to). This doesn't run until some time after the mloader function
finishes, when the data is returned from the server.

To do what you're looking for, you need to set up some kind of callback
system. There are various ways to do it, but here's an example:

function mloader(file) {
 var encLoad = new LoadVars();
 encLoad.onLoad = function(success) {
  var xmldata = encLoad.data;
  var decdata = RC4.decrypt(xmldata, "mykey");
  this.dummyXML = new XML();
  this.dummyXML.ignoreWhite = true;
  this.dummyXML.parseXML(decdata); };
 encLoad.load(file);
return encLoad
}
var loadListener = mloader("parent.xml.enc");
var xmlWatcher:Function =  function(prop, oldVal, newVal) {
    trace(newVal)
    loadListener.unwatch("dummyXML")
}
loadListener.watch("dummyXML", xmlWatcher);


This is a slightly odd way to do it, but it's just an example of how you
might fit it into your structure. The main point is that you can't expect
calls to a server to run synchronously, you have to set them going and then
set up some system that waits for them to complete - that's what the onLoad
call is for.

Danny 

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to