AS3参考按钮

时间:2012-04-11 16:54:20

标签: actionscript-3 flash-cs5

我该如何使这项工作?我需要从引用中删除单词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;
}

1 个答案:

答案 0 :(得分:1)

现在我了解你的问题,我建议如下。

  1. thiscontentMain以及其他任何内容中都有单独的按钮方法。然后根据需要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) {
        ...
    }