2012-09-25 51 views
0

我有一個ScrollPane,我正在嘗試向它添加Movieclips。那麼movieclip會添加,但是當它添加時,它將刪除先前添加的其他人,因此它只能一次顯示一個。AS3 ScrollPane影片剪輯正在刪除其他

我的代碼:

btnAdd.addEventListener(MouseEvent.CLICK, doadd); 
var X = 0; 
function doadd(Event):void { 
    var S:MovieClip=new MovieClip() 
    var mp:oItem = new oItem(); 
    mpane.source=S; 
    mp.y = X*25; 
    mp.txtIn.text = X; 
    MovieClip(mpane.content).addChild(mp); 
    X++; 
    mpane.update(); 
} 

回答

1

ScrollPane中只能有一個來源 - 這是由設計。

一個很好的方法來做你想做的事情,就是創建一個容器Sprite並將其作爲源代碼,然後將所有內容作爲子容器添加到容器中。

btnAdd.addEventListener(MouseEvent.CLICK, doadd); 
var X = 0; 

var container:Sprite = new Sprite(); //this will hold all your items and be the source of the scrollPane 
mpane.source = container; //set the source outside of your recuring doadd function 

function doadd(Event):void { 
    var mp:oItem = new oItem(); 
    mp.y = X*25; 
    mp.txtIn.text = X; 
    container.addChild(mp); //add to the container 
    X++; 
    mpane.update(); //you still need update everytime the contents of the scrollpane can potentially change size 
} 
+0

完美! 5顆星!正是我在找什麼。謝謝。 – Cyrus