What is the difference between that and this:

class SomeClass {
   private var a:Number = 3;
   function SomeClass(mc:MovieClip){
       var thisObj = this;
       // Set a reference to "this"
       mc.onRelease = function(){
           thisObj.onRelease();
       }
   }

   function onRelease(){
       trace("this.a: "+this.a);
   }
}

Not much, just cleaner and more convenient code. You code can be rewritten as:

import mx.utils.Delegate;
class SomeClass {
  private var a:Number = 3;
  function SomeClass(mc:MovieClip){
      mc.onRelease = Delegate.create(this,onRelease);
  }
  function onRelease(){
      trace("this.a: "+this.a);
  }
}

It's shorter, cleaner, less typing, and accomplishes exactly the same thing. Except you could also do this:

mc.onRelease = Delegate.create(_root.someotherclip,onRelease);

   ...or...

mc.onRelease = Delegate.create(_parent._parent,onRelease);

...and so on. You could, of course, do the same thing by defining thisObj as whatever scope you want to use, but it just seems cleaner and easier to do it with Delegate. The only downside being passing parameters, but that can be gotten around.

ryanm


_______________________________________________
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