OZONE Asylum
Forums
Multimedia/Animation
Flash, XML, class constructors
This page's ID:
11461
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
If you have the 7.2 (elipsis) update, there is a very useful new class built in called "Delegate" which really helps a lot with scoping things like callback functions. Also, adding datatypes to variables and functions REALLY helps me track down my all too frequent bone-headed booboos. I would rewrite your code as follows: [code]import mx.utils.Delegate; class GameData { private var game_xml:XML; // constructor function GameData(url:String):Void { game_xml = new XML(); game_xml.ignoreWhite = true; game_xml.onLoad = Delegate.create(this, gameOnLoad); game_xml.load(url); } private function gameOnLoad(success:Boolean):Void { // variable success is sent by event if (success) { trace("XML file contents: " + game_xml.firstChild.toString()); } else { trace ("document failed to load"); } } // rest of class, mostly getThing() functions that request specific nodes }[/code] So "this" (the class itself) is passed to the callback, and since game_xml is an instance variable the callback can find it no sweat. Google: Flash+Delegate and you will find a lot of info. Some of it digestable, some not. It sure can help with scope issues in class though. One by [url=http://www.senocular.com/news.php?subaction=showcomments&id=1092856365&archive=1094078028&start_from=&ucat=&go=archives]Senocular[/url] is excellent, and it appears in a more comprehensive [url=http://www.kirupa.com/web/xml/XMLspecificIssues3.htm]tutorial at Kirupa[/url]. Very good stuff. [small](Edited by [internallink=82]Steve[/internallink] on 01-04-2005 19:39)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »