代码如下:
/*作者:梦自在*/ /*mc的宽和高*/ var width_num:Number = 50; var height_num:Number = 40; /*空隙*/ var jiange_num:Number = 5; var x0:Number = Stage.width/2-150; var y0:Number = Stage.height/2-100; var num_num:Number = 0; var save_array:Array = new Array("A", "B", "C", "D", "E", "F", "G", "H"); /*初始化并打乱顺序*/ function init() { var num:Number; for (var i:Number = 0; i<=15; i++) { attachMovie("pic", "pic"+i, i); attachMovie("block", "block"+i, i+20); _root["pic"+i]._x = x0+Math.floor(i/4)*(width_num+jiange_num); _root["pic"+i]._y = y0+i%4*(height_num+jiange_num); _root["pic"+i].txt.text = save_array[Math.floor(num_num/2)]; num_num += 1; _root["block"+i]._x = x0+Math.floor(i/4)*(width_num+jiange_num); _root["block"+i]._y = y0+i%4*(height_num+jiange_num); } random_array_func(); } /*随机函数*/ function random_array_func() { var count:Number = 0; /*三角交换并打乱100次*/ while (count<=100) { var value1_num:Number = Math.floor(Math.random()*15); var value2_num:Number = Math.floor(Math.random()*15); if (value1_num != value2_num) { var xcin:Number; var ycin:Number; var block_xcin:Number; var block_ycin:Number; xcin = _root["pic"+value1_num]._x; _root["pic"+value1_num]._x = _root["pic"+value2_num]._x; _root["pic"+value2_num]._x = xcin; ycin = _root["pic"+value1_num]._y; _root["pic"+value1_num]._y = _root["pic"+value2_num]._y; _root["pic"+value2_num]._y = ycin; block_xcin = _root["block"+value1_num]._x; _root["block"+value1_num]._x = _root["block"+value2_num]._x; _root["block"+value2_num]._x = block_xcin; block_ycin = _root["block"+value1_num]._y; _root["block"+value1_num]._y = _root["block"+value2_num]._y; _root["block"+value2_num]._y = block_ycin; } else { var value1_num:Number = Math.floor(Math.random()*15); var value2_num:Number = Math.floor(Math.random()*15); } count++; } } function start_func() { var id_num:Number = 0; var save_txt:Number = 0; for (var i:Number = 0; i<=15; i++) { _root["pic"+i].i = i; _root["pic"+i].onRelease = function() { /*第一次开始选择时*/ if (id_num == 0) { _root["pic"+this.i].swapDepths(_root["block"+this.i]); save_txt = _root["pic"+this.i].txt.text; id_num += 1; } /*第二次开始选择时*/ else if (id_num == 1) { if (save_txt == _root["pic"+this.i].txt.text) { /*如果text一样则交换深度*/ _root["pic"+this.i].swapDepths(_root["block"+this.i]); id_num = 0; save_txt = 0; } } }; } } init(); start_func(); |
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |