各位在学习Flash的时候是否碰到这样的问题,图片如何分行排列, <BR />
每行几张,(或每列几张)下面是本人的一个简单的处理方法。用到Math对象的Math.floor,与作模运算罢了。 <BR />
先看看罢 <BR />
<BR />
<BR />
------------------------------------- <BR />
_x=20; <BR />
_y=20; <BR />
var imgs:MovieClip=createEmptyMovieClip("imgs",getNextHighestDepth()); <BR />
var col=4;//每行4个 <BR />
var row=5;//初始行数 <BR />
function test(col:Number){ <BR />
for(var i=0;i<15;i++){ <BR />
var n_mc:MovieClip=imgs.attachMovie("img000","img"+i+"_mc",i); <BR />
n_mc.id=i; <BR />
//n_mc._width=40; <BR />
//n_mc._height=30; <BR />
n_mc._x=i%col*(n_mc._width+5); <BR />
n_mc._y=Math.floor(i/col)*(n_mc._height+5); <BR />
n_mc.txt.selectable=false; <BR />
n_mc.txt.text="图片:"+i; <BR />
n_mc.btn.onPress=function(){ <BR />
trace(this._parent.id); <BR />
_root.selecttxt.text="你选择了第"+this._parent.id+"张"; <BR />
} <BR />
} <BR />
} <BR />
test(4); <BR />
btn.onRelease=function(){ <BR />
var n=Number(numtxt.text); <BR />
if(isNaN(n)){ <BR />
_root.selecttxt.text="你输入的不是数字"; <BR />
}else{ <BR />
test(n); <BR />
} <BR />
} <BR />
-----------------------
每行几张,(或每列几张)下面是本人的一个简单的处理方法。用到Math对象的Math.floor,与作模运算罢了。 <BR />
先看看罢 <BR />
<BR />
<BR />
------------------------------------- <BR />
_x=20; <BR />
_y=20; <BR />
var imgs:MovieClip=createEmptyMovieClip("imgs",getNextHighestDepth()); <BR />
var col=4;//每行4个 <BR />
var row=5;//初始行数 <BR />
function test(col:Number){ <BR />
for(var i=0;i<15;i++){ <BR />
var n_mc:MovieClip=imgs.attachMovie("img000","img"+i+"_mc",i); <BR />
n_mc.id=i; <BR />
//n_mc._width=40; <BR />
//n_mc._height=30; <BR />
n_mc._x=i%col*(n_mc._width+5); <BR />
n_mc._y=Math.floor(i/col)*(n_mc._height+5); <BR />
n_mc.txt.selectable=false; <BR />
n_mc.txt.text="图片:"+i; <BR />
n_mc.btn.onPress=function(){ <BR />
trace(this._parent.id); <BR />
_root.selecttxt.text="你选择了第"+this._parent.id+"张"; <BR />
} <BR />
} <BR />
} <BR />
test(4); <BR />
btn.onRelease=function(){ <BR />
var n=Number(numtxt.text); <BR />
if(isNaN(n)){ <BR />
_root.selecttxt.text="你输入的不是数字"; <BR />
}else{ <BR />
test(n); <BR />
} <BR />
} <BR />
-----------------------
回复Comments
{commenttime}{commentauthor}
{CommentUrl}
{commentcontent}