我是AS3的新手& Flash和不知道是否有人可以看看這個測試片。AS3動態加載和自動滾動隨機大小Movieclips
在我的Flash文件中,我有許多動畫片段隨機按動按鈕時動態添加到舞臺上。所有的動畫片段寬度相同,但高度不同,所有動畫片段的註冊點位於左下角(我在此階段僅用於測試目的)。
我想要做的是'自動'(而不是使用按鈕)從庫中向舞臺添加一串隨機選擇的mc's(也就是說mc應該連續添加 - 即一個另一個沒有間隙),從舞臺頂部向底部垂直向下自動滾動(以永不停止的傳送帶形式),然後在舞臺上不再可見時返回到圖書館。
任何人有任何想法。
//mc's are dynamically loaded & returned to the library
//mc's have 'export for Actionscript' property
//mc's have their anchor point placed bottom left
//stop all
stop();
//Speed of the vertical auto-scroll movement
var scrollSpeed:uint = 1;
//auto load random mc from library & place top left corner of stage
//load random mc via button for test purposes
McButton.addEventListener(MouseEvent.CLICK,attachMovieclip);
function attachMovieclip(event:MouseEvent):void{
//create a random number for choosing a mc from the array
var newNumber:int = (Math.random()*14)
//define the mc's
var mc1:Red01 = new Red01();
var mc2:Red02 = new Red02();
var mc3:Red03 = new Red03();
var mc4:Orange01 = new Orange01();
var mc5:Orange02 = new Orange02();
var mc6:Orange03 = new Orange03();
var mc7:Yellow01 = new Yellow01();
var mc8:Yellow02 = new Yellow02();
var mc9:Green01 = new Green01();
var mc10:Green02 = new Green02();
var mc11:Blue01 = new Blue01();
var mc12:Blue02 = new Blue02();
var mc13:Purple01 = new Purple01();
var mc14:Purple02 = new Purple02();
//create an array which holds all the mc's
var Mcarray:Array = newArray(mc1,mc2,mc3,mc4,mc5,mc6,mc7,mc8,mc9,mc10,mc11,mc12,mc13,mc14);
//add child (or random mc) to the stage
addChild(Mcarray[newNumber]);
//place mc at specific starting point coordinate - i.e. top of the stage
Mcarray[newNumber].x=0
Mcarray[newNumber].y=0
//trace mc random numeric value for test purposes
trace(newNumber);
//auto-scroll the randomly chosen mc vertically down the stage
stage.addEventListener(Event.ENTER_FRAME, moveScroll);
function moveScroll(e:Event):void{
Mcarray[newNumber].y += scrollSpeed;
//once first mc is completley on stage load the next random mc
//once a mc has completely left the bottom of the stage return it to the library
}
}
非常感謝您的意見,我會給你的想法一個旋轉,看看我可以進步多遠。 – Attila66 2013-05-02 06:47:25
哎呀,我只是重新讀你的問題,我以爲你的註冊點是左上角。同樣的邏輯適用,但將新剪輯的高度更改爲0,並檢查剪輯是否離屏,y等於(或更大)舞臺高度+對象高度。 – mitim 2013-05-02 07:29:16
已添加檢查以確定mc的全部高度何時可見&'在舞臺上',以及mc的全高度是否不可見&'關閉舞臺'且兩個功能都正常。 我還添加了一個刪除子語句,這樣當mc變得不可見時,它將從舞臺上移除並返回到庫中。這以可視的方式工作(即mc從舞臺消失),但根據輸出結果,mc(儘管不可見)仍然存在並且在進一步超過可見的階段極限之後行進。 – Attila66 2013-05-04 03:59:33