On 18 Jun 2006, at 18:22, D_C wrote:
the delegate class seems to be a hack to get around this - like "call
back (aka delegate) an instance of the class i am handing you"
why not just pass the method itself?

It is a standard way of solving scoping problems such as yours.

If you just pass the init method, init will be a new function called within the scope of xmlData - It will have access to the loaded xml and the XML object methods, but none of the properties or methods of MyWidget. In short it is the same as calling 'myWidgetInstance.init'. And could be written...

xmlData.onLoad = function( bSuccess:Boolean ):Void
{
  // I want to do layout stuff here
  // BUT I only have access to XML methods and properties!!!
// even if you could, sending me the xml as another parameter is no help,
  // I already have that info at my fingertips
  // I cannot call MyWidget methods or properties
};

By using Delegate as in my earlier message, init will run within the scope of the MyWidget instance, where it has access to all the methods and properties of MyWidget which xmlData from which you can extract what you need (assuming the boolean was true).

Search the Flashcoders archives for Delegate - there are plenty of threads offering alternative explanations and examples. Also check it out in the manual. And here... http://www.adobe.com/devnet/flash/ articles/eventproxy.html

Paul
--
[ http://www.creative-cognition.co.uk/ ]
_______________________________________________
[email protected]
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