2013-04-15 35 views
0

我必須將對象列表添加到數組中,以便可以訪問它們稍後,但由於某種原因,我添加的對象之前播放過,我將它們添加到顯示列表中。這裏是代碼:影片剪輯在它被添加到DisplayList之前工作嗎?

框架凡列表添加:

sunny.addEventListener(MouseEvent.CLICK, sunny_choice); 

function sunny_choice(E:MouseEvent) 
{ 
    var sunny_walkcycle: Sunny_Walkcycle = new Sunny_Walkcycle(); 
    var sunny_busstop : Sunny_BusStop = new Sunny_BusStop(); 
    var sunny_opening: Teacher_Opening_Sunny = new Teacher_Opening_Sunny(); 


    clothingArray.push(sunny_walkcycle); 
    clothingArray.push(sunny_busstop); 
    clothingArray.push(sunny_opening); 

    trace("Sunny"); 
    cleaner(); 
//cleaner just removes the event listener and asks it to go to the next frame 
} 

釷下一幀:

clothingArray [0].scaleX = -1; 

addChild (clothingArray [0]); 
clothingArray[0].x = 633; 
clothingArray[0].y = 174; 
clothingArray [0].stop(); 
clothingArray [0].addEventListener (MouseEvent.CLICK, transforming); 


function transforming (e:MouseEvent) { 
    if (clothingArray [0].currentFrame == clothingArray [0].totalFrames) { 
     clearall2(); 

    } 
    else{ 
    clothingArray [0].nextFrame(); 
    moving_background.nextFrame(); 
    } 

} 
function clearall2() { 
    clothingArray [0].removeEventListener (MouseEvent.CLICK, transforming); 
    removeChild (clothingArray [0]); 

    gotoAndStop (3); 
} 

的問題一:

addChild (clothingArray [1]); 
clothingArray[1].addEventListener (Event.ENTER_FRAME , busstop); 
trace ("The Current Frame is " + clothingArray [1].currentFrame); 
function busstop (d:Event) { 
     if (clothingArray [1].currentFrame == clothingArray [1].totalFrames) { 
     clearall3(); 

    } 
} 

function clearall3() { 
    removeChild (clothingArray [1]); 
    clothingArray[1].removeEventListener (Event.ENTER_FRAME , busstop); 

    } 

那麼究竟它確實是在幀3中的動畫片段開始播放之前它甚至被添加到顯示列表中,我不確定是什麼導致它...我不能在這個框架中單獨添加變量,因爲框架1中還有其他選項會導致我創建一個數組。

回答

1

假設Sunny_Walkcycle,Sunny_BusStop,Teacher_Opening_Sunny是MovieClip,爲什麼不在內存分配後直接使用stop()?

var sunny_walkcycle:Sunny_Walkcycle = new Sunny_Walkcycle(); 
    var sunny_busstop:Sunny_BusStop = new Sunny_BusStop(); 
    var sunny_opening:Teacher_Opening_Sunny = new Teacher_Opening_Sunny(); 

    sunny_walkcycle.stop(); 
    sunny_busstop.stop(); 
    sunny_opening.stop(); 

請確保您的MovieClip內部框架中沒有代碼會與您的控制代碼混淆。 像一個玩()...隱藏在某個地方。

你也可以嘗試(對於sunny_busstop),只需在陣列中推後:

clothingArray[1].stop(); 

clothingArray[1].gotoAndStop(1); 
1

是,一旦創建了一個影片剪輯將開始播放。它不需要添加到顯示列表來激活。這是理解非常重要的細節。

顯示列表僅確定顯示對象是否連接到階段層次結構。

解決方案...在創建後調用stop()方法,然後在將它們添加到顯示列表中時調用play()方法。

如果您在從顯示列表中刪除時沒有調用stop()方法,它將繼續吃掉cpu週期。如果你有很多影片剪輯與補間等,這可能是非常重要的。