0

所以我在屏幕上有 9 个按钮,我想要一个动作监听器:

-sudo code-

    frame3.buttion.event-handle({ this.title='clicked'})

-sudo code-

我现在拥有它的方式是有 9 个不同的按钮和事件处理程序大声笑,不酷。还有一种方法可以制作一个按钮数组并从该数组中添加和操作它们,比如 array[0].title=clicked?

4

2 回答 2

1

我会推荐一种完全不同的方法。

1) create a view and place all of the buttons in the view.
2) associated one eventListener to the view containing the buttons
3) when the view gets a click event, it will bubble up to the buttons; check the
  event.source.id to determine which button was clicked.
于 2013-06-27T01:27:53.897 回答
1

是的,

var buttons = new Array();
buttons[i] = Ti.UI.createButton({
    ..........
    //Add this
    my_id:i
});

这可以稍后再次获取

buttons[i].addEventListener('click',function(e)){ 
    var i = e.source.my_id;
    myAction[i] = Ti.Media.createSound({ url: sounds[i] }).play();
    Ti.API.info("clicked button: " + i+ " : "+ myAction[i]);
});

或者

buttons[i].addEventListener('click',function(e)){ 
    var i = e.source.my_id;
    doSomething(i); //function that handles click.
});
于 2013-06-25T16:57:28.953 回答