Re: [Flashcoders] The Delegate class ...

2006-06-16 Thread John Giotta

I practically live by Delegate  EventDispatcher
___
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


Re: [Flashcoders] The Delegate class ...

2006-06-15 Thread Ian Thomas

On 6/15/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:


Alot of people complain that you can't pass parameters with delegate. Well
you can, a multiple of ways, and if you structure your code with some
forethought, you can have it pass params if you are delegating a function
structured do so.


Alternatively you could use (or write, as I did) a slightly more
advanced version of Delegate which takes function passing into
account.

A couple of popular variants are:

http://www.dynamicflash.co.uk/2005/02/delegate-class-refined/

and

http://www.person13.com/articles/proxy/Proxy.htm

They let you write things like:

myButton1.onRelease=Delegate.create(this,onSomeButtonPressed,green);
myButton2.onRelease=Delegate.create(this,onSomeButtonPressed,red);

:

function onSomeButtonPressed(colour:String)
{
  trace(The +red+ button was pressed!);
}

and also to pass additional parameters to existing callback function.

HTH,
 Ian
___
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


Re: [Flashcoders] The Delegate class ...

2006-06-15 Thread eka

Hello :)

You can use my Delegate implementation too in VEGAS Framework :

-
http://svn1.cvsdude.com/osflash/vegas/AS2/trunk/src/vegas/events/Delegate.as(
vegas.events.Delegate class)
- http://svn1.cvsdude.com/osflash/vegas/AS2/trunk/bin/test/vegas/events/(example
with Delegate and Event Model EventDispatcher, etc..)
- http://svn1.cvsdude.com/osflash/vegas/AS2/trunk/src/vegas/events/ (package
vegas.events)

More information about VEGAS : http://osflash.org/vegas

EKA+ :)

2006/6/15, Ian Thomas [EMAIL PROTECTED]:


On 6/15/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Alot of people complain that you can't pass parameters with delegate.
Well
 you can, a multiple of ways, and if you structure your code with some
 forethought, you can have it pass params if you are delegating a
function
 structured do so.

Alternatively you could use (or write, as I did) a slightly more
advanced version of Delegate which takes function passing into
account.

A couple of popular variants are:

http://www.dynamicflash.co.uk/2005/02/delegate-class-refined/

and

http://www.person13.com/articles/proxy/Proxy.htm

They let you write things like:

myButton1.onRelease=Delegate.create(this,onSomeButtonPressed,green);
myButton2.onRelease=Delegate.create(this,onSomeButtonPressed,red);

:

function onSomeButtonPressed(colour:String)
{
   trace(The +red+ button was pressed!);
}

and also to pass additional parameters to existing callback function.

HTH,
  Ian
___
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


___
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


[Flashcoders] The Delegate class ...

2006-06-14 Thread Stephen Ford
Hello All,
 
Can anyone confirm that the Delegate class is only helpful when using 
components ?
 
Or should it also be used for events outside the component framework ?
 
No doubt it depends on what your trying to achieve, but just generally 
speaking, what do you think.
 
Thanks,
Stephen.
 
 ___
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


Re: [Flashcoders] The Delegate class ...

2006-06-14 Thread James Marsden

The delegate class is a godsend for so many things...


// inside a class:

mc.onEnterFrame = mx.utils.Delegate.create(this, main);

function main()
{
   // the mc is calling my method, and I can access all my properties 
as if I was calling it myself

}




Stephen Ford wrote:


Hello All,

Can anyone confirm that the Delegate class is only helpful when using 
components ?

Or should it also be used for events outside the component framework ?

No doubt it depends on what your trying to achieve, but just generally 
speaking, what do you think.

Thanks,
Stephen.
 


___
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


Re: [Flashcoders] The Delegate class ...

2006-06-14 Thread Andreas Rønning

i use Delegate for most handlers. Never used it with components

- A

Stephen Ford wrote:


Hello All,

Can anyone confirm that the Delegate class is only helpful when using 
components ?

Or should it also be used for events outside the component framework ?

No doubt it depends on what your trying to achieve, but just generally 
speaking, what do you think.

Thanks,
Stephen.

___
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
 


___
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


RE: [Flashcoders] The Delegate class ...

2006-06-14 Thread Chuck Hoffman
Delegate simply tells the code you're delegating to run in the scope of
a particular object.  So there are all sorts of ways you could use it.
It basically creates a function that runs in the scope you indicate, but
can be attached to any object.  This most commonly comes in handy in the
context of event listeners, but there's nothing about Delegate that
makes it inherently tied to the component framework.  It works with any
kind of objects.





 CHUCK HOFFMAN
PROGRAMMER  
T8DESIGN.COM | P 319.266.7574 - x150 | 877.T8IDEAS | F 888.290.4675


This e-mail, including attachments, is covered by the Electronic
Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential, and
may be legally privileged. If you are not the intended recipient, you
are hereby notified that any retention, dissemination, distribution, or
copying of this communication is strictly prohibited. Please reply to
the sender that you have received the message in error, and then please
delete it. Thank you.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Stephen
Ford
Sent: Tuesday, June 13, 2006 8:18 PM
To: flashcoders
Subject: [Flashcoders] The Delegate class ...

Hello All,
 
Can anyone confirm that the Delegate class is only helpful when using
components ?
 
Or should it also be used for events outside the component framework ?
 
No doubt it depends on what your trying to achieve, but just generally
speaking, what do you think.
 
Thanks,
Stephen.
 
 ___
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
___
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


Re: [Flashcoders] The Delegate class ...

2006-06-14 Thread eka

Hello :)

you can show your mx package in Flash installation : C:\Program
Files\Macromedia\Flash 8\en\First Run\Classes

In this directory you find mx.utils.Delegate class !

Now in flash you can use this class :

[code]

import mx.utils.Delegate ;

var o = {} ;
o.toString = function () {
   return myCustomScope ;
}

var action:Function = function () {
   trace(   + this +  : action) ;
}

// test1 - scope is the _root
action() ;

// test2 - scope is o your custom scope.
var myAction:Function = Delegate.create(o, action) ;
myAction() ;

// test3 - scope is a MovieClip with mc this instance's name

mc.onRelease = action ; // if you release your mc, use action with mc scope
(classic)

mc.onPress = Delegate.create(o, action) ; // if you press your mc, use
custom scope

[/code]

EKA+ :)

2006/6/14, Stephen Ford [EMAIL PROTECTED]:


Hello All,

Can anyone confirm that the Delegate class is only helpful when using
components ?

Or should it also be used for events outside the component framework ?

No doubt it depends on what your trying to achieve, but just generally
speaking, what do you think.

Thanks,
Stephen.

___
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


___
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


Re: [Flashcoders] The Delegate class ...

2006-06-14 Thread Rich Rodecker

the Delegate class is useful whenever you are trying to control the
scope of a method call.  Normall, when you do something like:

//code on _root
my_mc.onPress = function(){
 trace(this);
}

the onPress function is assigned to my_mc.  this means that when you
use this inside code inside the onPress function, you will be
referring to my_mc (the code above would output _level0.my_mc).
Most of the time, people will want to create a separate function to
run when the onPress event occurs (or when an onLoad event occurs in
an XML or LoadVars object).

//code on the _root timeline
my_mc.onPress = Delegate.create(this, myPressFunction);

function myPressFunction(){
 trace (this)
}

this code would output _level0. This means that you can still run
the function in it's normal scope and still have normal references to
other variables and methods in the same scope.  This comes in most
handy whe you are dealing with classes, where you'd want to reference
methods and properties in your class when an event occurs, but you
don't want the mehod (such as onPress) being scoped to the object that
produced the event.



On 6/14/06, Andreas Rønning [EMAIL PROTECTED] wrote:

i use Delegate for most handlers. Never used it with components

- A

Stephen Ford wrote:

Hello All,

Can anyone confirm that the Delegate class is only helpful when using 
components ?

Or should it also be used for events outside the component framework ?

No doubt it depends on what your trying to achieve, but just generally 
speaking, what do you think.

Thanks,
Stephen.

 ___
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


___
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


___
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


Re: [Flashcoders] The Delegate class ...

2006-06-14 Thread Ian Thomas

Delegate, sadly, is a necessity.

I very rarely use components.

I use Delegate all the time. (Or rather, my own hand-rolled version,
which deals properly with arguments - there are a bunch of such
replacement versions knocking around.)

See here for more info on Delegate and its usage:
http://www.osflash.org/flashcoders/as2#handling_scope_in_event_handlers

Ian

On 6/14/06, Stephen Ford [EMAIL PROTECTED] wrote:

Hello All,

Can anyone confirm that the Delegate class is only helpful when using 
components ?

Or should it also be used for events outside the component framework ?

No doubt it depends on what your trying to achieve, but just generally 
speaking, what do you think.

Thanks,
Stephen.
 ___
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


___
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


Re: [Flashcoders] The Delegate class ...

2006-06-14 Thread js
While not as elegant, you can get around this issue delegate-free with 
the following:


class SomeClass {

private var a:Number = 3;

function SomeClass(mc:MovieClip){

var thisObj = this;
// Set a reference to this

mc.onRelease = function(){

thisObj.onRelease.call(thisObj);
}

}

function onRelease(){

trace(this.a: +this.a);

}
}

--

Joseph

James Marsden wrote:

The delegate class is a godsend for so many things...


// inside a class:

mc.onEnterFrame = mx.utils.Delegate.create(this, main);

function main()
{
   // the mc is calling my method, and I can access all my properties as 
if I was calling it myself

}




Stephen Ford wrote:


Hello All,

Can anyone confirm that the Delegate class is only helpful when using 
components ?


Or should it also be used for events outside the component framework ?

No doubt it depends on what your trying to achieve, but just generally 
speaking, what do you think.


Thanks,
Stephen.
 


___
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



___
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


Re: [Flashcoders] The Delegate class ...

2006-06-14 Thread Aaron Buchanan
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);

}
}


On 6/14/06 1:39 PM, js [EMAIL PROTECTED] wrote:

 While not as elegant, you can get around this issue delegate-free with
 the following:
 
 class SomeClass {
 
 private var a:Number = 3;
 
 function SomeClass(mc:MovieClip){
 
 var thisObj = this;
 // Set a reference to this
 
 mc.onRelease = function(){
 
 thisObj.onRelease.call(thisObj);
 }
 
 }
 
 function onRelease(){
 
 trace(this.a: +this.a);
 
 }
 }
 
 --
 
 Joseph
 
 James Marsden wrote:
 The delegate class is a godsend for so many things...
 
 
 // inside a class:
 
 mc.onEnterFrame = mx.utils.Delegate.create(this, main);
 
 function main()
 {
// the mc is calling my method, and I can access all my properties as
 if I was calling it myself
 }
 
 
 
 
 Stephen Ford wrote:
 
 Hello All,
 
 Can anyone confirm that the Delegate class is only helpful when using
 components ?
 
 Or should it also be used for events outside the component framework ?
 
 No doubt it depends on what your trying to achieve, but just generally
 speaking, what do you think.
 
 Thanks,
 Stephen.
  
 
 ___
 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
 
 
 ___
 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


___
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


Re: [Flashcoders] The Delegate class ...

2006-06-14 Thread stacey
Do you really need the call bit ? Can you not just do something like:

var host=this;
mc.onRelease=function(){
 host.fireFunction();
}
function fireFunction(){
trace(function called)
}


You can use delegates for more than just components - I use delegate most
often when I want an item/class to have a public no-op function that I can
overwrite outside of it - like a layoutclass that draws items to the
stage, i might want to overwrite what it does when its finished laying
stuff out- a totally made up example might be :



var LM:LayoutManager=new LayoutManager();
LM.onLayoutComplete=Delegate.create(this,layoutChildren);
LM.doLayout(grid,items);

function layoutChildren():Void{
 trace( layout is done);
}

Alot of people complain that you can't pass parameters with delegate. Well
you can, a multiple of ways, and if you structure your code with some
forethought, you can have it pass params if you are delegating a function
structured do so. I would argue that if its not flexible enough for you ,
then maybe you need to revisit your architecure and determine if Delegate
is  what you need or if you're really in need of using something else such
athe dispatch scenerio.  One thing to remember is that Delegate is just a
function, and therefore you can add properties to it and have a reference
to it. I don't know how proper that is, but it works.

var myDelegate:Function =mx.utils.Delegate.create(this,onComplete);
myDelegate.someProperty=foo;

myButton.addEventListener(click,myDelegate);

function onComplete(obj:Object):Void{
  trace(arguments.caller.someProperty)
}




 While not as elegant, you can get around this issue delegate-free with
 the following:

 class SomeClass {

   private var a:Number = 3;

   function SomeClass(mc:MovieClip){

   var thisObj = this;
   // Set a reference to this

   mc.onRelease = function(){

   thisObj.onRelease.call(thisObj);
   }

   }

   function onRelease(){

   trace(this.a: +this.a);

   }
 }

 --

 Joseph

 James Marsden wrote:
 The delegate class is a godsend for so many things...


 // inside a class:

 mc.onEnterFrame = mx.utils.Delegate.create(this, main);

 function main()
 {
// the mc is calling my method, and I can access all my properties
 as
 if I was calling it myself
 }




 Stephen Ford wrote:

 Hello All,

 Can anyone confirm that the Delegate class is only helpful when using
  components ?

 Or should it also be used for events outside the component framework
 ?

 No doubt it depends on what your trying to achieve, but just
 generally  speaking, what do you think.

 Thanks,
 Stephen.


 ___
 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


 ___
 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



___
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


Re: [Flashcoders] The Delegate class ...

2006-06-14 Thread David Rorex

The whole point of a Delegate type class is to eliminate having to type
those 4 lines of code every time you want to handle an event from somwhere
else without messing up the scope.

-David R

On 6/14/06, Aaron Buchanan [EMAIL PROTECTED] wrote:


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);

}
}


On 6/14/06 1:39 PM, js [EMAIL PROTECTED] wrote:

 While not as elegant, you can get around this issue delegate-free with
 the following:

 class SomeClass {

 private var a:Number = 3;

 function SomeClass(mc:MovieClip){

 var thisObj = this;
 // Set a reference to this

 mc.onRelease = function(){

 thisObj.onRelease.call(thisObj);
 }

 }

 function onRelease(){

 trace(this.a: +this.a);

 }
 }

 --

 Joseph

 James Marsden wrote:
 The delegate class is a godsend for so many things...


 // inside a class:

 mc.onEnterFrame = mx.utils.Delegate.create(this, main);

 function main()
 {
// the mc is calling my method, and I can access all my properties
as
 if I was calling it myself
 }




 Stephen Ford wrote:

 Hello All,

 Can anyone confirm that the Delegate class is only helpful when using
 components ?

 Or should it also be used for events outside the component framework ?

 No doubt it depends on what your trying to achieve, but just generally
 speaking, what do you think.

 Thanks,
 Stephen.




___
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


Re: [Flashcoders] The Delegate class ...

2006-06-14 Thread js
Absolutely nothing. I have no idea why I put call there. :) I use call 
 a fair amount to manipulate scope and I think I just typed it out of 
habit.


Joseph

Aaron Buchanan wrote:

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);

}

}


On 6/14/06 1:39 PM, js [EMAIL PROTECTED] wrote:


While not as elegant, you can get around this issue delegate-free with
the following:

class SomeClass {

private var a:Number = 3;

function SomeClass(mc:MovieClip){

var thisObj = this;
// Set a reference to this

mc.onRelease = function(){

thisObj.onRelease.call(thisObj);
}

}

function onRelease(){

trace(this.a: +this.a);

}
}

--

Joseph

James Marsden wrote:

The delegate class is a godsend for so many things...


// inside a class:

mc.onEnterFrame = mx.utils.Delegate.create(this, main);

function main()
{
   // the mc is calling my method, and I can access all my properties as
if I was calling it myself
}




Stephen Ford wrote:


Hello All,

Can anyone confirm that the Delegate class is only helpful when using
components ?

Or should it also be used for events outside the component framework ?

No doubt it depends on what your trying to achieve, but just generally
speaking, what do you think.

Thanks,
Stephen.
 


___
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



___
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



___
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



___
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


Re: [Flashcoders] The Delegate class ...

2006-06-14 Thread ryanm

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