学习Flash 网站元件根据场景大小自动定位的方法
这是我整理的一个控制的版本
使用的时候直接调用函数
setPosition(你要控制的元件名称,"定位方法");
就可以了
提示
top方法为y轴顶端对齐x轴居中对齐
bottom为方法为y轴底部对齐x轴居中对齐
left方法为y轴居中对齐x轴左对齐
right为方法为y轴居中对齐x轴右对齐
center方法为y轴居中对齐x轴居中对齐
------------------------------------AS---------------------------------------
Stage.scaleMode = "noScale";
Stage.align = "LT";
function setPosition(mcName, position) {
if (position == "left") {
mcName._x = 0;
mcName._y = Stage.height/2-mcName._height/2;
} else if (position == "top") {
mcName._y = 0;
mcName._x = Stage.width/2-mcName._width/2;
} else if (position == "right") {
mcName._x = Stage.width-mcName._width;
mcName._y = (Stage.height-mcName._height)/2;
} else if (position == "bottom") {
mcName._x = (Stage.width-mcName._width)/2;
mcName._y = Stage.height-mcName._height;
} else if (position == "center") {
mcName._x = (Stage.width-mcName._width)/2;
mcName._y = (Stage.height-mcName._height)/2;
} else {
trace("方法名错误,无"+position+"此种对齐方式."+"\n"+"您可以自定义定位方式,或者修改方法名为已定义方法."+"\n"+"提示:"+"\n"+"top方法为y轴顶端对齐x轴居中对齐"+"\n"+"bottom为方法为y轴底部对齐x轴居中对齐"+"\n"+"left方法为y轴居中对齐x轴左对齐"+"\n"+"right为方法为y轴居中对齐x轴右对齐"+"\n"+"center方法为y轴居中对齐x轴居中对齐"+"\n"+"-------------------------------"+"\n"+"\n");
}
}
//---------------------初始化元件位置
setPosition(top,"top");
setPosition(right,"right");
setPosition(bottom,"bottom");
setPosition(left,"left");
setPosition(center,"center");
//---------------------开始监听
Stage.addListener(_root);
function onResize() {
setPosition(top,"top");
setPosition(right,"right");
setPosition(bottom,"bottom");
setPosition(left,"left");
setPosition(center,"center");
}
//---------------------停止监听
//Stage.removeListener(_root);
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |