主要是firstNum
var yname:Array = ["ya1","ya2","ya3","ya4","ya5","ya6","ya7","ya8"];
var Yname:Array = ["Ya1","Ya2","Ya3","Ya4","Ya5","Ya6","Ya7","Ya8"];
//主要是这个firstNum我看不懂他在后面程序执行中为什么是0
var firstNum:int;
var secondNum:int = 7* Math.random();
this.addEventListener(MouseEvent.CLICK,clickF);
function clickF(event:MouseEvent){
//第二个随机数不能和第一个相同,也不能比第一个随机数小1否则与前一个相邻
switch(secondNum)
{
case firstNum:
trace("重复,重新选择");
secondNum= 7* Math.random();
break;
case firstNum-1:
trace("相邻,重新选择");
secondNum= 7* Math.random();
break;
default:
//yname[firstNum]是个字符串,[yname[firstNum]]才是实例名称
var type:Class = getDefinitionByName(Yname[secondNum]) as Class;//如Flash.display.Sprite;
//生成新的实例
var mycode = new type();
mycode.width =this.parent[yname[secondNum]].width;
mycode.height = this.parent[yname[secondNum]].height;
this.parent.addChild(mycode);
//为什么在这里firstNum一直是0
trace(firstNum,secondNum , Yname[secondNum]);
mycode.x = this.x -this.width/2+3 ;
mycode.y = this.y -this.height/2 +3;
firstNum=secondNum;
secondNum= 7* Math.random();
//这里firstNum的确不是0
trace(firstNum);
break;
}
}
源方档(flash cs5):
全-求助排列对象-4.fla
(111.48 KB, 下载次数: 192)
功能是:单击第一行的空白格会有一个相应的图片编码填到相应的位置上,但是不能重复和原来排列出现相邻情况
代码位置:空白格子元件的时间轴上复制代码
|