Andreas Rønning wrote:
2. What the hell is going on with "this" here

class ParseXML{
   private var xmlDoc:XML;
   private function handleXML(){
       trace(this);
   }
   function ParseXML(url:String){
       xmlDoc = new XML();
       xmlDoc.ignoreWhite = true;
       xmlDoc.onLoad = handleXML;
       xmlDoc.load(url);
   }
}

I'd write that like this:

class ParseXML {
    private var _xmlDoc : XML;
    function ParseXML( url : String ) {
        _xmlDoc = new XML();
        _xmlDoc.ignoreWhite = true;
        _xmlDoc.onLoad = function () {
            trace( this );
        };
        _xmlDoc.load( url );
    }
}

Clearer? The original version isn't defining a method for the class, it's defining a function and assigning it to a variable. In the spirit of calling a spade a spade, it's better to define an anonymous function where it's actually used.

- Robert
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to