I recently ran into a problem that I solved with Delegate. I thought
that others might run into this problem.
I built a button component that included validation of a set of other
components. The user of the button would name a set of required
components in a property values dialog. When the button initialized, it
adds listeners for the 'correct' events that the other components emit
(tutoring application). I found things worked fairly well initially but
after adding a second copy of my button to the stage and assigning a
common required field, I found that the first button no longer responded
to the 'correct' event. To fix this problem, I incorporated Delegate
when assigning the listener. A line of the code is shown below where
'ShowCorrect' is the event and componentsShowCorrect is a method in my
button class.
componentName.addEventListener("showCorrect", Delegate.create(this,
componentsShowCorrect));
In the past, I had ran across Delegate and found it a bit confusing. I
have generally relied on assigning a reference to the class (i.e. this)
to a variable of the object that listens
componentName["realThis"] = this
But this didn't work for my situation and I had to go with Delegate. I
found a nice demonstration of Delegate in the book 'Using ActionScript
2.0 Components with Macromedia Flash 8' It seems that Macromedia has
made some nice strides in component documentation with Flash 8.
_______________________________________________
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