2013-03-25 4 views
-2

Я никогда не работал с AS2, и мне было интересно, как вы преобразовали бы это в AS3? Любая помощь будет принята с благодарностью.Преобразовать код 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._yscale = 80; 
      $mc._rotation = random(2)-1; 
      random(2) == 0 ? $mc._xscale = 80:$mc._xscale = -80; 
      nr++; 
    } else { 
     nr = 0; 
    } 
} 
+2

В будущем, было бы лучше, чтобы показать, что вы уже пробовали, а затем сосредоточиться на ваш вопрос на части, вы не можете понять самостоятельно. – BadFeelingAboutThis

ответ

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 
} 
Смежные вопросы