Actionscript 3 将AS2代码转换为AS3
我从未使用过AS2,我想知道如何将其转换为AS3?任何帮助都将不胜感激Actionscript 3 将AS2代码转换为AS3,actionscript-3,flash,actionscript-2,Actionscript 3,Flash,Actionscript 2,我从未使用过AS2,我想知道如何将其转换为AS3?任何帮助都将不胜感激 stop(); var nr:Number = 0; var $mc:MovieClip; this.onEnterFrame = function (){ if(nr < 100) { $mc = this.attachMovie("fire", "fire"+nr, nr); $mc._x = random(4)-2; $mc
stop();
var nr:Number = 0;
var $mc:MovieClip;
this.onEnterFrame = function (){
if(nr < 100)
{
$mc = this.attachMovie("fire", "fire"+nr, nr);
$mc._x = random(4)-2;
$mc._yscale = 80;
$mc._rotation = random(2)-1;
random(2) == 0 ? $mc._xscale = 80:$mc._xscale = -80;
nr++;
} else {
nr = 0;
}
}
stop();
变量编号:编号=0;
var$mc:MovieClip;
this.onEnterFrame=函数(){
如果(nr<100)
{
$mc=此。附件(“火灾”、“火灾”+nr,nr);
$mc.x=随机(4)-2;
$mc.\u yscale=80;
$mc._旋转=随机(2)-1;
随机(2)==0?$mc.xscale=80:$mc.xscale=-80;
nr++;
}否则{
nr=0;
}
}
请参见下面重新分解的代码中的内联注释:
stop();
var ctr:int = 0; //var to keep track of how many instances you've made of the Fire class
var mc:DisplayObject; //temporary object to hold the created instance of the FIre class
this.addEventListener(Event.ENTER_FRAME,onEnterFrame); //this is how you do enter frame handlers in AS3
function onEnterFrame(e:Event):void {
if(ctr < 100)
{
/*
instead of doing the attach movie clip, you have give your Fire object it's own class / actionscript linkage, then you instantiate it and add it to the display list with addChild()
*/
mc = new FireClass();
mc.x = random(4)-2; //in AS3 there is just Math.Random(), which returns a number between 0 and 1. I've made a random() function below that emulates the old random() function. Also, ._x & ._y are now just .x & .y
mc.scaleY = .8; //scaleX/Y have changed names, and 0 - 100 is now 0 - 1.
mc.rotation = random(2)-1;
mc.scaleX = random(2) == 0 ? .8 : -.8;
addChild(mc);
ctr++;
} else {
this.removeEventListener(Event.ENTER_FRAME,onEnterFrame); //remove the listener since ctr has reached the max and there's no point in having this function running every frame still
}
}
function random(seed:int = 1):Number {
return Math.Random() * seed;
//if you're expecting a whole number, you'll want to to this instead:
return Math.round(Math.random() * seed); //if seed is 4, this will return 0,1,2,3 or 4
}
stop();
var ctr:int=0//var来跟踪您对Fire类创建了多少个实例
var-mc:DisplayObject//用于保存已创建的FIre类实例的临时对象
this.addEventListener(事件.输入_FRAME,onEnterFrame)//这就是在AS3中输入帧处理程序的方式
函数一帧间(e:事件):无效{
如果(ctr<100)
{
/*
您没有执行附加电影剪辑,而是为Fire对象提供了自己的类/actionscript链接,然后实例化它并使用addChild()将其添加到显示列表中
*/
mc=新的FireClass();
mc.x=random(4)-2;//在AS3中,只有Math.random(),它返回一个介于0和1之间的数字。我在下面创建了一个random()函数,它模拟了旧的random()函数。另外,.x和.y现在只是.x和.y
mc.scaleY=.8;//scaleX/Y已经更改了名称,0-100现在是0-1。
mc.旋转=随机(2)-1;
mc.scaleX=random(2)==0?.8:-.8;
addChild(mc);
ctr++;
}否则{
this.removeEventListener(Event.ENTER_FRAME,onEnterFrame);//删除侦听器,因为ctr已达到最大值,让此函数仍在每帧运行没有意义
}
}
函数随机(种子:int=1):数字{
返回Math.Random()*种子;
//如果您期望的是一个整数,则应改为:
返回Math.round(Math.random()*seed);//如果seed为4,则返回0,1,2,3或4
}
今后,最好展示您已经尝试过的内容,然后将问题集中在您自己无法理解的部分。