Re: [Flashcoders] Can u combine....
I linke your solution and though I usually prefer to reuse objects such as loader, I'm not totally against creating a loader per request since in some situations it can be handy. But let me tell you, you have a subtle bug in your code. You need to pin down your loader somehow, because otherwise, since it's local to the function, it could be garbage collected. I was under the impression that an active loader would not be collected. It's rare that this happens, but it's possible. I've learned this the hard way, and it took a while and some hair pulling to figure out where the problem was (I was using a Loader object to load images, but the same principle applies to URLLoaders). This could be fixed by storing your loader in an instance-scoped array, and then removing it (and its handlers) when the loader's job is done (either because it succeded or failed), using the event.target reference to find the loader in the array. Cheers Juan Pablo Califano 2010/2/26 Valentin Schmidt v...@dasdeck.com Juan Pablo Califano wrote: Another option: function loadXML(dfile:String,arg1:Object,arg2:Array):void { urlLoader.load(new URLRequest(dfile)); urlLoader.addEventListener(Event.COMPLETE, function(e:Event):void { parseXml(e,arg1,arg2); }); } and another option: save this as file myURLLoader.as package { import flash.net.URLLoader; public class myURLLoader extends URLLoader { public var params:Object; } } and then use something like this: function loadXML(dfile:String):void { var urlLoader:myURLLoader = new myURLLoader(); // add arbitrary custom parameters here urlLoader.params = {foo:23, bar:hello world}; urlLoader.load(new URLRequest(dfile)); urlLoader.addEventListener(Event.COMPLETE, parseXML); } function parseXML(e:Event):void { trace(e.target.params.foo); trace(e.target.params.bar); xmlFile:new XML(e.target.data); // ... } cheers, valentin ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Can u combine....
Can you set a private var other functions can use? -- Kenneth Kawamoto http://www.materiaprima.co.uk/ On 26 February 2010 14:24, Lehr, Theodore ted_l...@federal.dell.com wrote: ..how to combine: function loadXML(dfile:String):void { urlLoader.load(new URLRequest(dfile)); urlLoader.addEventListener(Event.COMPLETE, parseXML); } function parseXML(e:Event):void { xmlFile:new XML(e.target.data); totalBars = xmlFile.children().length(); } My goal is to send the first function additional parameters that would be used in additonal function calls right now I do not see how to send those on to parseXML my thought was if there was a way to combine these two functions - it would be easier ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Can u combine....
Ted - this should do what you're after: package { public class MyData { private var _myVarA:String; private var _myVarB:Number; private function loadXML(dfile:String, myValueA:String, myValueB:Number):void { _myVarA = myValueA; _myVarB = myValueB; urlLoader.load(new URLRequest(dfile)); urlLoader.addEventListener(Event.COMPLETE, parseXML); } private function parseXML(e:Event):void { //Use _myVarA and _myVarB here. xmlFile:new XML(e.target.data); totalBars = xmlFile.children().length(); } } } Jason Merrill Bank of America Global Learning Learning Performance Solutions Join the Bank of America Flash Platform Community and visit our Instructional Technology Design Blog (note: these are for Bank of America employees only) ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Can u combine....
Another option: function loadXML(dfile:String,arg1:Object,arg2:Array):void { urlLoader.load(new URLRequest(dfile)); urlLoader.addEventListener(Event.COMPLETE, function(e:Event):void { parseXml(e,arg1,arg2); }); } function parseXML(e:Event,arg1:Object,arg2:Array):void { xmlFile:new XML(e.target.data); totalBars = xmlFile.children().length(); } This method has a drawback (and is usually frowned upon) because you cannot remove the listener. In this case, though, I don't think this is a problem (the loader seems to be owned by the class) Cheers Juan Pablo Califano 2010/2/26 Lehr, Theodore ted_l...@federal.dell.com ..how to combine: function loadXML(dfile:String):void { urlLoader.load(new URLRequest(dfile)); urlLoader.addEventListener(Event.COMPLETE, parseXML); } function parseXML(e:Event):void { xmlFile:new XML(e.target.data); totalBars = xmlFile.children().length(); } My goal is to send the first function additional parameters that would be used in additonal function calls right now I do not see how to send those on to parseXML my thought was if there was a way to combine these two functions - it would be easier ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Can u combine....
Juan Pablo Califano wrote: Another option: function loadXML(dfile:String,arg1:Object,arg2:Array):void { urlLoader.load(new URLRequest(dfile)); urlLoader.addEventListener(Event.COMPLETE, function(e:Event):void { parseXml(e,arg1,arg2); }); } and another option: save this as file myURLLoader.as package { import flash.net.URLLoader; public class myURLLoader extends URLLoader { public var params:Object; } } and then use something like this: function loadXML(dfile:String):void { var urlLoader:myURLLoader = new myURLLoader(); // add arbitrary custom parameters here urlLoader.params = {foo:23, bar:hello world}; urlLoader.load(new URLRequest(dfile)); urlLoader.addEventListener(Event.COMPLETE, parseXML); } function parseXML(e:Event):void { trace(e.target.params.foo); trace(e.target.params.bar); xmlFile:new XML(e.target.data); // ... } cheers, valentin ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders