Since I posted about the wonderfulness of the Delegate class for AS2 I've learned a little bit more useful info I'd like to pass on. As you may remember, the Delegate class is very useful for managing the scope of your code. The biggest problem I still ran into though was passing and accessing variables from my the custom handlers I made with the Delegate class. Thankfully , there is an easy way to pass variables. Simply add it as an attribute to the event handler.
E.G.
//import the Delegate class
import mx.utils.Delegate;
//add a variable to pass to your handler
something.onPress = Delegate.create(this, someHandler);
something.onPress.myVariable = "pass me";
//now to access that variable use caller
function someHandler(){
var passedVar= arguments.caller.myVariable;
trace(passedVar);
}
Voila! Now you can enjoy the satisfaction of passing variables to your custom handlers.
Travels
Showing posts with label delegate. Show all posts
Showing posts with label delegate. Show all posts
Thursday, January 10, 2008
Subscribe to:
Posts (Atom)