欢迎光临

木子屋

标题: 几个FlashActionScript

作者: dnawo

日期: 2007-06-16 07:18 PM

分类: 网页设计

内容: 一、匀速直线运动(元件名称:btn1)
复制内容到剪贴板 程序代码var num1:Number = 0;
var num2:Number = 0;
function moveto(){
num1 += 1;
num2 += 1;
btn1._x = num1;
btn1._y = num2;
}
setInterval(this, "moveto", 100);
二、加速直线运动(元件名称:btn1,text1)
复制内容到剪贴板 程序代码var speed:Number = 10; //循环速度
var v:Number = 10; //初始速度
var a:Number = 5; //加速度
var t:Number= 0 ; //时间初始值
var l:Number;
function moveto(){
t = t + speed/1000;
v = v + a*t;
l = v*t + a*Math.pow(t,2)/2;
btn1._x = l;
btn1._y = 100;
text1.text = v; //瞬时速度
}
setInterval(this, "moveto", speed);
三、随机变化位置(元件名称:btn1)
复制内容到剪贴板 程序代码var num1:Number,num2:Number;
function moveto(){
num1 = random(300);
num2 = random(300);
btn1._x = num1;
btn1._y = num2;
}
setInterval(this, "moveto", 100);
四、逐渐放大(元件名称:btn1)
复制内容到剪贴板 程序代码var num1:Number = 0;
var num2:Number = 0;
function zoomto(){
num1 += 1;
num2 += 1;
btn1._width = num1;
btn1._height = num2;
}
setInterval(this, "zoomto", 100);
五、颜色设置(元件名称:btn1)
复制内容到剪贴板 程序代码on (release) {
var NewColor = new Color(btn2);
NewColor.setRGB(0x000000);
}
六、渐隐渐现(元件名称:btn1)
复制内容到剪贴板 程序代码var num1:Number = 0;
var ifalg:Number = 0; //0:显；1:隐
function changealpha(){
if(num1==100){ ifalg=1;}
if(num1==0){ ifalg=0;}
if(ifalg==0){
num1 += 1;
}else{
num1 -= 1;
}
btn1._alpha = num1;
}
setInterval(this, "changealpha", 10);
七、矩形运动(元件名称:btn1)
复制内容到剪贴板 程序代码var num1:Number = 0;
var num2:Number = 0;
function moveto(x1:Number,y1:Number,x2:Number,y2:Number,x3:Number,y3:Number,x4:Number,y4:Number){
if(num1==0 && num2==0){
num1 = x1;
num2 = y1;
}
if(num1>=x1 && num2==y1){
num1 += 2;
num2 = y1;
}
if(num1==x2 && num2>=y2){
num1 = x2;
num2 += 2;
}
if(num1<=x3 && num2==y3){
num1 -= 2;
num2 = y3;
}
if(num1==x4 && num2<=y4){
num1 = x4;
num2 -= 2;
}
//trace(num1 + ":" + num2);
btn1._x = num1;
btn1._y = num2;
}
setInterval(this, "moveto", 10,100,100,200,100,200,200,100,200);
八、多边形运动(元件名称:btn1)
复制内容到剪贴板 程序代码var speed:Number = 50; //移动速度 单位：px/s
var speed2:Number = 10; //循环间隔 单位：ms
var time:Number; //总时间
var time2:Number = 0; //计时
var Lx:Number,Ly:Number; //单位时间位移
var Intervalid:Number;
var x1:Number = btn1._x; //初始X坐标
var y1:Number = btn1._y; //初始Y坐标
var x2:Number,y2:Number; //终点X、Y坐标
var arrA:Array; //数组：路径各节点坐标
var iflag:Number = 0; //标识符
var i:Number;
//函数：计算Lx,Ly
function returnLxLy(x:Number,y:Number){
var L:Number; //总路径
x2 = x;
y2 = y;
L = Math.sqrt(Math.pow(Math.abs(Math.abs(x2)-Math.abs(x1)),2) + Math.pow(Math.abs(Math.abs(y2)-Math.abs(y1)),2));
time = L / speed;
Lx = ((x2-x1)*speed*speed2)/(L*1000);
Ly = ((y2-y1)*speed*speed2)/(L*1000);
}
//函数：移动元件
//参数格式：x1,y1,x2,y2,x3,y3...
function moveto(arr:String){
if(iflag==0){
iflag = 1;
i = 1;
arrA = arr.split(",")
returnLxLy(arrA[0],arrA[1]);
Intervalid = setInterval(this, "moveto", speed2);
}
time2 = time2 + speed2/1000;
if(time2>time){
time2 = 0;
clearInterval(Intervalid);
if(2*i<arrA.length){
returnLxLy(arrA[2*i],arrA[2*i+1]);
Intervalid = setInterval(this, "moveto", speed2);
i += 1;
}
}
x1 = x1 + Lx;
y1 = y1 + Ly;
btn1._x = x1;
btn1._y = y1;
}
moveto("100,100,200,100,200,200,100,200,100,100")
八、系统时间(元件名称:text1)
复制内容到剪贴板 程序代码function settime(){
var date1 = new Date();
text1.text = date1.getHours() + ":" + date1.getMinutes() + ":" + date1.getSeconds();
}
setInterval(this, "settime", 1000);
九、跟随鼠标走动的小孩(元件名称:girl)
复制内容到剪贴板 程序代码function moveto(){
girl._x = _root._xmouse;
girl._y = _root._ymouse;
}
setInterval(this, "moveto", 100);
十、鼠标点击移动的小孩(元件名称:girl,btn1)
复制内容到剪贴板 程序代码btn1._width = Stage.width;
btn1._height = Stage.height;
on (release) {
girl._x = _root._xmouse;
girl._y = _root._ymouse;
}
十一、圆周运动
复制内容到剪贴板 程序代码var m:Number = 0;
var n:Number = 0;
var Intervalid:Number;
var v:Number = 2;
lineStyle(1);
function drawCircle(x:Number, y:Number, r:Number){
if(n==0){moveTo(x, y+r);}
n += v*Math.PI/180;
mc._x = x+r*Math.sin(m);
mc._y = y+r*Math.cos(m);
m = n;
}
Intervalid = setInterval(this, "drawCircle", 1,200,100,100);

+ 查看当前日志评论 (1)

登录

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 2.910 ms

返回

标题: 几个FlashActionScript

你没有权限发表评论

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 2.910 ms

返回

暂无评论

返回

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 2.988 ms

返回