艺虎动画 > Flash教学课件:选择填空题的制作

Flash教学课件:选择填空题的制作

翼虎动漫   2010-7-20

 

 

先看选择填空题:
/UploadTeach/201006/2010063012721267.swf

仿照下面有个英文选择填空题做的,写得很马虎,不过基本是那样子了。如高手们有空就帮优化一下:

var subjectArray:Array=new Array("中国的尼姑最早是何时出现的","谁是兽中之王","《义勇军进行曲》是哪部电影的主题歌",

"屈原是春秋时代哪国人","中国第一部彩色故事片是");

var selectArray:Array=new Array("A. 夏朝","B.唐朝","C.南北朝","D.金朝","A.大象","B.老虎","C.狮子","D.动物园园长",

"A.上甘岭","B.高山下的花环","C.风云儿女","D.英雄儿女","A.齐国","B.楚国","C.燕国","D.赵国","A.霍元甲","B.祝福","C.一双绣花鞋","D.黄丝带");

//将所有选择答案放在一个数组里

var answerArray:Array=new Array("C","D","C","B","B");

//将所有答案放在一个数组里



var showArray:Array=new Array();

var nameArray:Array=new Array();

var scoreArray:Array=new Array();



var scoreNum:Number=100/subjectArray.length;

var score:int;

var totalScore:int;

var isplay:Boolean;





var field:TextField=new TextField();

var format:TextFormat=new TextFormat("Tahoma");

field.defaultTextFormat=format;

field.text="成绩: "+"  "+"分";

addChild(field);

field.y=300;

field.x=200;







for (var j:int=0; j<subjectArray.length; j++) {

        var subjectText:TextField=new TextField();

        subjectText.x=20;

        subjectText.y=40*j+20;

        subjectText.width=300;

        subjectText.mouseEnabled=false;

        subjectText.defaultTextFormat=format;

        subjectText.text=(j+1)+"."+subjectArray[j]+" ? ";

        addChild(subjectText);



        var show:Show=new Show();

        show.y=40+j*40;

        show.x=20;

        show.showText.mouseEnabled=false;

        show.indexText.text=(j+1)+".";

        show.indexText.mouseEnabled=false;

        show.judgeText.mouseEnabled=false;

        showArray.push(show);

        addChild(show);





}



for (var i:uint=0; i<selectArray.length; i++) {

        var selectButton:Button=new Button();

        addChild(selectButton);

        selectButton.x = 100+i%4*110;

        selectButton.y = 40+Math.floor(i/4)*40;

        //排列

        selectButton.buttonText.text=selectArray[i];

        selectButton.name=i.toString();

        nameArray.push(selectArray[i].charAt(0));

        //将数组里各索引第一个字符装进数组

        selectButton.addEventListener(MouseEvent.CLICK,selectButtonClick);



}





function selectButtonClick(event:MouseEvent) {

        var id:int=int(event.target.name);

        if (!isplay) {

                //-----------------------------------------------------------

                if (id<4) {

                        showArray[0].showText.text=nameArray[id];

                }

                if (id>=4 && id<8) {

                        showArray[1].showText.text=nameArray[id];

                }

                if (id>=8 && id<12) {

                        showArray[2].showText.text=nameArray[id];

                }

                if (id>=12 && id<16) {

                        showArray[3].showText.text=nameArray[id];

                }

                if (id>=16 && id<20) {

                        showArray[4].showText.text=nameArray[id];

                }

                //左边括号里显示的选项,这里有缺点

                //--------------------------------------------------------------

        }

}





var button:Button=new Button();

addChild(button);

button.x=300;

button.y=300;

button.buttonText.text="提交";

button.addEventListener(MouseEvent.CLICK,buttonClick);

function buttonClick(event:MouseEvent) {

        isplay=!isplay;

        if (isplay) {

                button.buttonText.text="清除";

                for (var ii:uint=0; ii<subjectArray.length; ii++) {

                        scoreArray.push(score);

                        if (showArray[ii].showText.text==answerArray[ii]) {

                                showArray[ii].judgeText.text="√";

                                scoreArray[ii]=scoreNum;



                        } else {

                                showArray[ii].judgeText.text="×";

                                scoreArray[ii]=0;



                        }

                        totalScore+=scoreArray[ii];

                }

                field.text="成绩: "+totalScore.toString()+" 分";



        } else {

                totalScore=0;

                button.buttonText.text="提交";

                field.text="成绩: "+"  "+"分";

                for (var jj:uint=0; jj<subjectArray.length; jj++) {

                        showArray[jj].showText.text="";

                        showArray[jj].judgeText.text="";

                }

        }

}
源文件附件下载:选择填空题.rar