1

I am having a situation with my actionscript/flex front end.

 for each (var sym:String in ["A","B","C"]) {

                const handler = function (data:Object):void { Alert.show(sym); }                

                asyncCallback(handler);

   }

I am expecting to have 3 Alert windows containing A, B and C. But the actual result is 3 alert windows all showing C !

1 Answer 1

1

This one is a bit tricky. You have to wrap your handler creation inside another function.

try:

for each(var sym:String in ["A","B","C"]) {
    function createHandler(val:String):Function {
        var handler = function(data:Object):void { 
            trace(val); 
        }
        return handler;
    }
    var handler:Function = createHandler(sym);
    asyncCallback(handler);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.