1

我怎样才能使这项工作?我需要从引用中删除单词 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;
}
4

1 回答 1

1

既然我理解了你的问题,我会推荐以下内容。

  1. this对 in和 incontentMain以及任何其他按钮有单独的方法。然后在适当的情况下通过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;
    }
    
  2. 为您拥有的方法添加额外的逻辑。

    if (this[...] != null) {
        ...
    }else if (contentMain[...] != null) {
        ...
    }
    
于 2012-04-11T17:58:59.013 回答