我该如何使这项工作?我需要从引用中删除单词Button,以引用将要着色的实际项目。提前谢谢。
disagreeButton.addEventListener(MouseEvent.ROLL_OVER, mouseRollOver);
contentMain.clickButton1.addEventListener(MouseEvent.ROLL_OVER, mouseRollOver);
function mouseRollOver(e:MouseEvent):void {
var c:Color = new Color();
c.setTint (0xFFFFFF, 1);
//the issue is this line:
this[e.target.name.replace( "Button", "" )].transform.colorTransform = c;
}
答案 0 :(得分:1)
现在我了解你的问题,我建议如下。
在this
和contentMain
以及其他任何内容中都有单独的按钮方法。然后根据需要this[...]
或contentMain[...]
访问对象。
disagreeButton.addEventListener(MouseEvent.ROLL_OVER, mainMouseRollOver);
contentMain.clickButton1.addEventListener(MouseEvent.ROLL_OVER, contentMainMouseRollOver);
function mainMouseRollOver(e:MouseEvent):void {
mouseRolloverLogic(this[e.target.name.replace( "Button", "" )];
}
function contentMainMouseRollOver(e:MouseEvent):void {
mouseRolloverLogic(contentMain[e.target.name.replace( "Button", "" )];
}
function mouseRolloverLogic(item:DisplayObject):void {
var c:Color = new Color();
c.setTint (0xFFFFFF, 1);
item.transform.colorTransform = c;
}
为您拥有的方法添加额外的逻辑。
if (this[...] != null) {
...
}else if (contentMain[...] != null) {
...
}