How do I pass a function as a parameter in Action Script?

2

Can anyone tell me what kind of object allows me to do an array of value and function similar to the code below and action script 3? If it were in Java it would give something like this:

My Interface:

package test;

public interface MyInterface {

    public void alert();
}

And my class using Interface:

package test;

import java.util.HashMap;
import java.util.Map;

public class MyClass {

    public static void main(String[] args) {
        Map<Integer, MyInterface> map = new HashMap<>();

        map.put(1, new MyInterface() {
            @Override
            public void alert() {
                System.out.println("valor 1");

            }
        });

        map.put(2, new MyInterface() {
            @Override
            public void alert() {
                System.out.println("valor 2");

            }
        });
    }

}
    
asked by anonymous 20.01.2015 / 19:08

1 answer

2

You can try to use an array instead of HashMap , and literal objects as value:

var map = [];
map.push({
    alert: function() { trace("aaaaa") }
});
map.push({
    alert: function() { trace("bbbbb") }
});
map[0].alert(); // aaaaa
map[1].alert(); // bbbbb
    
20.01.2015 / 20:41