Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何更改单击的按钮_Actionscript 3 - Fatal编程技术网

Actionscript 3 如何更改单击的按钮

Actionscript 3 如何更改单击的按钮,actionscript-3,Actionscript 3,目前,我有3个按钮,它们的名称分别为:开始、关于和统计。这3个按钮都是movieClip。它们都在一个容器中(也是一个movieClip)名称为group\u btn。因此,我的问题是,当我仅为所有3个元素使用一个MouseEventListener时,如何告诉确切的元素更改其ScaleX和ScaleY。 我确实认为我必须检测哪个被点击了,但之后我不知道该怎么办。 到目前为止,我有以下代码: private function onAddedToStage(eve:Event):void {

目前,我有3个按钮,它们的名称分别为:开始、关于和统计。这3个按钮都是movieClip。它们都在一个容器中(也是一个movieClip)名称为group\u btn。因此,我的问题是,当我仅为所有3个元素使用一个MouseEventListener时,如何告诉确切的元素更改其ScaleX和ScaleY。 我确实认为我必须检测哪个被点击了,但之后我不知道该怎么办。 到目前为止,我有以下代码:

private function onAddedToStage(eve:Event):void {
        trace("we are good to go");
        this.group_btn.start_btn.addEventListener(MouseEvent.MOUSE_OVER, makeButtonBigger)
        this.group_btn.start_btn.addEventListener(MouseEvent.MOUSE_OUT, makeButtonSmaller)
        this.group_btn.about_btn.addEventListener(MouseEvent.MOUSE_OVER, makeButtonBigger)
        this.group_btn.about_btn.addEventListener(MouseEvent.MOUSE_OUT, makeButtonSmaller)
        this.group_btn.stats_btn.addEventListener(MouseEvent.MOUSE_OVER, makeButtonBigger)
        this.group_btn.start_btn.addEventListener(MouseEvent.MOUSE_OUT, makeButtonSmaller)

    }

private function makeButtonBigger(ev:MouseEvent):void{
        var nameOfButton:String = ev.currentTarget.name;
        //this.group_btn.nameOfButton.scaleX = 1.2  <--- doesnt work
        trace(nameOfButton)

    }
添加的statage(eve:Event)上的私有函数:void{ trace(“我们可以走了”); this.group\u btn.start\u btn.addEventListener(MouseEvent.MOUSE\u OVER,makeButtonBigger) this.group_btn.start_btn.addEventListener(MouseEvent.MOUSE_OUT,makeButtonSmaller) this.group\u btn.about\u btn.addEventListener(MouseEvent.MOUSE\u OVER,makeButtonBigger) this.group_btn.about_btn.addEventListener(MouseEvent.MOUSE_OUT,makeButtonSmaller) this.group_btn.stats_btn.addEventListener(MouseEvent.MOUSE_OVER,makeButtonBigger) this.group_btn.start_btn.addEventListener(MouseEvent.MOUSE_OUT,makeButtonSmaller) } 私有函数makeButtonBigger(ev:MouseeEvent):无效{ var nameOfButton:String=ev.currentTarget.name;
//this.group_btn.nameOfButton.scaleX=1.2您需要使用方括号访问该属性;这种方式意味着有一个按钮字面上被称为“nameOfButton”,这就是它失败的原因。请尝试以下操作:

private function makeButtonBigger(ev:MouseEvent):void{
    var nameOfButton:String = ev.currentTarget.name;
    this.group_btn[nameOfButton].scaleX = 1.2;
    trace(nameOfButton);
}
这将使用实际捕获的字符串,而不是变量名本身

尽管如此,您也可以直接从事件的
currentTarget
属性访问该按钮:

private function makeButtonBigger(ev:MouseEvent):void{
    ev.currentTarget.scaleX = 1.2;
}