2011-04-11 5 views
0

비트 맵을 스테이지에로드 한 다음 AS 코드를 사용하여 완전히 트위닝하려고합니다. 다음은 작동하지만 스테이지에 새로운 비트 맵 이미지를 추가하면 마지막 비트 맵 이미지가 남겨져 동일한 비트 맵이로드됩니다.기본 ActionScript 3 스프라이트 트위닝

아이디어가 있으십니까? 나는 "removeChild (myLoader);"를 추가하려고 시도했다. 그러나 그것은 아무것도하지 않았다. 많은 감사합니다. 당신이 실제로 하나의 객체를 이동하는 것이 아니라, 서로 다른 위치에 여러 개체를로드 -

import flash.display.MovieClip; 
import flash.events.*; 

stage.frameRate = 31; 
var a =0; 

btn111.addEventListener(MouseEvent.CLICK, go); 

function go(event:MouseEvent):void 
{ 
    this.addEventListener(Event.ENTER_FRAME, drawrect); 

    function drawrect(evt:Event) 
    { 
     // Create a new instance of the Loader class to work with 
     var myLoader:Loader=new Loader(); 

     // Create a new URLRequest object specifying the location of the external image file 
     var myRequest:URLRequest=new URLRequest("logo.png"); 

     // Call the load method and load the external file with URLRequest object as the parameter 
     myLoader.load(myRequest); 

     // Add the Loader instance to the display list using the addChild() method 
     addChild(myLoader); 

     // Position image 
     myLoader.x = 100; 
     myLoader.y = a++; 

     if(a > 50) 
     { 
      //removeChild(box); 
      removeEventListener(Event.ENTER_FRAME, drawrect); 
     } 
    } 
} 

답변

0

귀하의 문제는 모든 프레임에, 당신이 실제로 표시 목록에 새 자식을 추가하고 있다는 것입니다. 로더를 프레임 단위로 실행되지 않는 다른 함수로 옮기거나 if 블록이 존재하는지 여부를 확인하는 if 블록에 캡슐화해야합니다.

시도해보십시오. (당신이 정말로 당신이 그런 식으로 할 것인지 모른다면 .....하지만 당신은 아마 그렇게되고 싶지 않아)

import flash.display.MovieClip; 
import flash.events.*; 

stage.frameRate = 31; 
var a =0; 

private var myLoader:Loader; 

btn111.addEventListener(MouseEvent.CLICK, go); 

function go(event:MouseEvent):void 
{ 
    this.addEventListener(Event.ENTER_FRAME, drawrect); 

    function drawrect(evt:Event) 
    { 
     if (myLoader == NULL) 
     { 
      // Create a new instance of the Loader class to work with 
      myLoader:Loader=new Loader(); 

      // Create a new URLRequest object specifying the location of the external image file 
      var myRequest:URLRequest=new URLRequest("logo.png"); 

      // Call the load method and load the external file with URLRequest object as the parameter 
      myLoader.load(myRequest); 

      // Add the Loader instance to the display list using the addChild() method 
      addChild(myLoader); 
     } 

     // Position image 
     myLoader.x = 100; 
     myLoader.y = a++; 

     if(a > 50) 
     { 
      //removeChild(box); 
      removeEventListener(Event.ENTER_FRAME, drawrect); 
     } 
    } 
} 

또한, 나는 기능 내에서 기능에 무리를 줄 수있다.

행운을 빈다.