skaterdav85 Posted September 5, 2011 Share Posted September 5, 2011 I have 2 methods and 2 properties in an Actionscript 3 class. The first method fetchXMLData() gets data from an XML file. In the addEventListener method on the urlLoader object, I pass it a listener which tries to set the returned data to the xmlData class property. However, it never sets it, and I know the data comes back because I can alert out urlLoader.data using the mx.controls.Alert component. Anyone have an idea of what is going on? public var urlLoader:URLLoader;public var xmlData:String; public function getXMLData():String { return this.xmlData;} public function fetchXMLData():void { urlLoader = new URLLoader(); urlLoader.addEventListener(Event.COMPLETE, function(e:Event):void { this.xmlData = urlLoader.data; }); urlLoader.load(new URLRequest("tours.xml")); } Link to comment Share on other sites More sharing options...
justsomeguy Posted September 6, 2011 Share Posted September 6, 2011 Can you verify that the event handler is executing? Link to comment Share on other sites More sharing options...
skaterdav85 Posted September 7, 2011 Author Share Posted September 7, 2011 So I found out that using anonymous functions in AS can be kind of weird and people recommend not using them in your Actionscript. Instead of using an anonymous function, when the Complete event occurs, I call a class method and set the property. It's also worth noting that I need to dispatch a custom event so that I can listen for the custom event and call the getter method when the response is completed. When you dispatch a custom event, don't use an anonymous function like what I am doing here. It ends up getting dispatched to a different context and you can't listen for the event on your object. Im not sure I like Actionscript 3. Apparently it is based on EcmaScript 4 which many JS developers disliked. Maybe it just takes getting used to, but overall the Flex framework and Actionscript 3 are kind of neat. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.