【问题标题】:SimpleButtons display but are not active on the stageSimpleButtons 在舞台上显示但未激活
【发布时间】:2011-06-06 15:29:26
【问题描述】:

我编写了一个名为 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);

}

感谢您的帮助!!!

【问题讨论】:

    标签: flash actionscript-3 events actionscript button


    【解决方案1】:

    我相信您只是缺少 ButtonTile 类中的 hitTestState 属性:

    this.hitTestState = TileColor(0);
    

    【讨论】:

      猜你喜欢
      • 2014-08-07
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 2017-11-08
      • 1970-01-01
      • 1970-01-01
      • 2013-01-12
      • 2011-01-27
      相关资源
      最近更新 更多