2013-03-25 1 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 
}