FLASH AS3.0,我怎么把这段代码写成一个方法?
varjiaodu1:int=260varjiaodu2:int=260clock.zhen.rotation=0clock.zhen2.rotation=0vartim...
var jiaodu1:int = 260
var jiaodu2:int = 260
clock.zhen.rotation = 0
clock.zhen2.rotation = 0
var time1:uint = setInterval(xuanzhuan1,10)
var time2:uint = setInterval(xuanzhuan2,20)
//this.addEventListener(Event.ENTER_FRAME,xuanzhuan)
function xuanzhuan1():void
{
var b = clock.zhen.rotation
if(b<0)
{
b = 180+(180+clock.zhen.rotation)
}
if(b < jiaodu1)
{
clock.zhen.rotation += 2;
}
else
{
clock.zhen.rotation = jiaodu1;
clearInterval(time1)
}
}
function xuanzhuan2():void
{
var b = clock.zhen2.rotation
if(b<0)
{
b = 180+(180+clock.zhen2.rotation)
}
if(b < jiaodu2)
{
clock.zhen2.rotation += 2;
}
else
{
clock.zhen2.rotation = jiaodu2;
clearInterval(time2)
}
}
======================================
以上代码是一个仪表盘的效果,因为一个舞台上可能有N个仪表盘,我要是反复的复制粘贴,那么代码就太多了,有朋友说可以写成个方法,用function,然后每次调用就行了,这个我该怎么写?怎么个方法最好,谁能帮帮我?谢谢啦 展开
var jiaodu2:int = 260
clock.zhen.rotation = 0
clock.zhen2.rotation = 0
var time1:uint = setInterval(xuanzhuan1,10)
var time2:uint = setInterval(xuanzhuan2,20)
//this.addEventListener(Event.ENTER_FRAME,xuanzhuan)
function xuanzhuan1():void
{
var b = clock.zhen.rotation
if(b<0)
{
b = 180+(180+clock.zhen.rotation)
}
if(b < jiaodu1)
{
clock.zhen.rotation += 2;
}
else
{
clock.zhen.rotation = jiaodu1;
clearInterval(time1)
}
}
function xuanzhuan2():void
{
var b = clock.zhen2.rotation
if(b<0)
{
b = 180+(180+clock.zhen2.rotation)
}
if(b < jiaodu2)
{
clock.zhen2.rotation += 2;
}
else
{
clock.zhen2.rotation = jiaodu2;
clearInterval(time2)
}
}
======================================
以上代码是一个仪表盘的效果,因为一个舞台上可能有N个仪表盘,我要是反复的复制粘贴,那么代码就太多了,有朋友说可以写成个方法,用function,然后每次调用就行了,这个我该怎么写?怎么个方法最好,谁能帮帮我?谢谢啦 展开
2个回答
展开全部
//调用参数(目标,指针1的角度,指针2的角度,指针1的运行间隔时间,指针2的运行间隔时间)
function Clock(clock:MovieClip,angle1:int,angle2:int,setTime1:int,setTime2:int):void {
var jiaodu1:int=angle1;
var jiaodu2:int=angle2;
clock.zhen.rotation=0;
clock.zhen2.rotation=0;
var time1:uint=setInterval(xuanzhuan1,setTime1);
var time2:uint=setInterval(xuanzhuan2,setTime2);
//this.addEventListener(Event.ENTER_FRAME,xuanzhuan)
function xuanzhuan1():void {
var b=clock.zhen.rotation;
if (b<0) {
b = 180+(180+clock.zhen.rotation);
}
if (b<jiaodu1) {
clock.zhen.rotation+=2;
} else {
clock.zhen.rotation=jiaodu1;
clearInterval(time1);
}
}
function xuanzhuan2():void {
var b=clock.zhen2.rotation;
if (b<0) {
b = 180+(180+clock.zhen2.rotation);
}
if (b<jiaodu2) {
clock.zhen2.rotation+=2;
} else {
clock.zhen2.rotation=jiaodu2;
clearInterval(time2);
}
}
}
//3个表盘的调用,参数不同效果不同。
Clock(clock1,260,260,10,20);
Clock(clock2,260,200,10,20);
Clock(clock3,260,260,10,50);
我强烈要求加分,因为我从桌面还得双击我的flash CS4,然后还要新建文件,还要画指针,最后还要测试。。。
function Clock(clock:MovieClip,angle1:int,angle2:int,setTime1:int,setTime2:int):void {
var jiaodu1:int=angle1;
var jiaodu2:int=angle2;
clock.zhen.rotation=0;
clock.zhen2.rotation=0;
var time1:uint=setInterval(xuanzhuan1,setTime1);
var time2:uint=setInterval(xuanzhuan2,setTime2);
//this.addEventListener(Event.ENTER_FRAME,xuanzhuan)
function xuanzhuan1():void {
var b=clock.zhen.rotation;
if (b<0) {
b = 180+(180+clock.zhen.rotation);
}
if (b<jiaodu1) {
clock.zhen.rotation+=2;
} else {
clock.zhen.rotation=jiaodu1;
clearInterval(time1);
}
}
function xuanzhuan2():void {
var b=clock.zhen2.rotation;
if (b<0) {
b = 180+(180+clock.zhen2.rotation);
}
if (b<jiaodu2) {
clock.zhen2.rotation+=2;
} else {
clock.zhen2.rotation=jiaodu2;
clearInterval(time2);
}
}
}
//3个表盘的调用,参数不同效果不同。
Clock(clock1,260,260,10,20);
Clock(clock2,260,200,10,20);
Clock(clock3,260,260,10,50);
我强烈要求加分,因为我从桌面还得双击我的flash CS4,然后还要新建文件,还要画指针,最后还要测试。。。
追问
必须加分!!太感激了!另外还一个小问题~我想让表针根据XML提供的数值转动,v1.text是XML里的取值,这样写对吗?Clock(clock1,int(260*Number(v1.text)/110),260,10,20);比如数值是80,就转到80那里停···数值是99.5,就在99.5那停。另外如果只有1个表针的话,是把Clock(clock1,260,260,10,20);中的其中一个260改成什么?去掉怎么去?
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询