SimpleButtons显示但在舞台上不活动

时间:2011-06-06 15:29:26

标签: flash actionscript-3 events actionscript button

我编写了一个名为ButtonTile的类来扩展SimpleButton类。然后我创建一个ButtonTile对象数组,并以网格形式将它们添加到我的舞台上。

当我运行代码时,所有ButtonTile对象都出现在舞台上,但它们不可点击,并且它们的颜色不会因其过度和向下状态而改变。

这是ButtonTile类的代码:

package com.shakti.gameState{

import flash.display.*;

public class ButtonTile extends SimpleButton {

    public var id:int;
    public var quizId:int;
    public var subjectId:int;
    public var points:int;
    public var questionTxt:String;
    public var order:int;
    public var option:Array;

    public function ButtonTile(newId:int, newQuizId:int, newSubId:int, newPoints:int, qtxt:String, newOrder:int, newOption:Array) {
        this.id=newId;
        this.quizId=newQuizId;
        this.subjectId=newSubId;
        this.points=newPoints;
        this.questionTxt=qtxt;
        this.order=newOrder;
        this.option=newOption;
        this.upState=TileColor(0);
        this.downState=TileColor(1);
        this.overState=TileColor(2);
        this.useHandCursor = true;
        this.enabled = true;
    }

    public function TileColor(stateFlag:int):Shape{

        var newShape:Shape=new Shape();
        if (stateFlag == 0){
            trace('hi');
            newShape.graphics.beginFill(0x000000);
        }
        else if (stateFlag == 1) {
            newShape.graphics.beginFill(0x00ff00);
        }
        else {
            newShape.graphics.beginFill(0x303030);
        }
        newShape.graphics.drawRect(0,0,70,50);
        newShape.graphics.endFill();
        return(newShape);
    }
}

这是创建ButtonTile对象数组的代码:

        public function MakeButtons():Array{

        var a:int = 0;

        for (var i:int = 0; i < quizState.subjects.length; ++i){

            for (var e:int = 0; e < quizState.subjects[i].quizQuestions.length; ++e){ 

                var id:int = quizState.subjects[i].quizQuestions[e].id;
                var quizId:int = quizState.subjects[i].quizQuestions[e].quizId;
                var subjectId:int = quizState.subjects[i].quizQuestions[e].subjectId;
                var points:int = quizState.subjects[i].quizQuestions[e].points;
                var questionTxt:String = quizState.subjects[i].quizQuestions[e].question;
                var order:int = quizState.subjects[i].quizQuestions[e].order;
                var option:Array = quizState.subjects[i].quizQuestions[e].option;

                tempTile = new ButtonTile(id, quizId, subjectId, points, questionTxt, order, option);                   

                buttons[a] = tempTile;
                ++a;
            }
        }
        return buttons;
    }

在将每个对象添加到舞台时,会将事件侦听器添加到该对象中。

for (var i:int = 0; i < buttons.length; ++i){
var tempTile:ButtonTile;
tempTile = buttons[i];
tempTile.x = boxPoints[i].x;
tempTile.y = boxPoints[i].y;
tempTile.addEventListener(MouseEvent.CLICK, PopQuest);
addChild(tempTile);

}

感谢您的帮助!!!

1 个答案:

答案 0 :(得分:1)

我相信你只是错过了ButtonTile类中的hitTestState属性:

this.hitTestState = TileColor(0);