自己从来没有做过Flash,看看下面这点代码,可是我费了好久长做出来的,发现ActionScript 3.0与平时其他语言开发工具有很大差别。
MCXY是一些切割好的图片小格,在Firerwork中用web切片工具生成。(为了图像质量问题,费了好多脑细胞,最后发现原来很简单!).
很简单,能改进的还有好多…
//记录缺省的空格
var CurCol=1;
var CurRow=3;
//记录每个格的长宽(正方形)
var BoxSize=100;
//记录格子的行列数(行列相同)
var BoxRow=3;
MC12.addEventListener(MouseEvent.CLICK,clickHandler);
MC13.addEventListener(MouseEvent.CLICK,clickHandler);
MC21.addEventListener(MouseEvent.CLICK,clickHandler);
MC22.addEventListener(MouseEvent.CLICK,clickHandler);
MC23.addEventListener(MouseEvent.CLICK,clickHandler);
MC32.addEventListener(MouseEvent.CLICK,clickHandler);
MC33.addEventListener(MouseEvent.CLICK,clickHandler);
function clickHandler(me:MouseEvent):void
{
var ClickRow=0;
var ClickCol=0;
//计算点击的是哪个格
ClickRow=Math.round((me.stageY+50)/100);
ClickCol=Math.round((me.stageX+50)/100);
//判断能否移动
if ( (ClickCol==CurCol && ( (ClickRow-1)==CurRow || (ClickRow+1)==CurRow ) )
||((ClickRow==CurRow) && ((ClickCol-1)==CurCol || (ClickCol+1)==CurCol)))
{
me.currentTarget.x=(CurCol-1)*100;
me.currentTarget.y=(CurRow-1)*100;
CurCol=ClickCol;
CurRow=ClickRow;
}
}