2012-09-25 52 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