2013-05-02 107 views
0

我是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 
} 
} 

回答

0

關閉我的頭頂,所以它可能是一個有點粗糙,但....

開始第一個剪輯,並將其存儲在一個「onscreenClips」陣列(將被用於像一個隊列):

1.)將「onscreenClips」中的起始剪輯設置爲y = - 高度 這會將剪輯的底部對齊到舞臺的頂部。

然後你進入框架內環路:

1)移動任何剪輯「onscreenClips」下降速度

2)檢查是否在「onscreenClips」的第一個對象已經觸底還(y屬性等於舞臺高度)。如果是這樣,請將其從顯示中刪除(因爲它現在不在屏幕上)並且不在隊列中。第一個對象始終是隊列中的「最老的」。 3)檢查「onscreenClips」中的最後一個對象是否已經到達舞臺的頂部(y屬性已經達到0並且不再是負值)。這意味着頂部邊緣與舞臺頂部對齊,如果再向下移動,則會出現間隙。如果發生這種情況,則將下一個剪輯集添加到y = -height,然後將其推送到隊列中。

4.)繼續,直到沒有更多的對象添加。然後繼續檢查步驟2的條件,直到「屏幕快照」數組/隊列爲空。

+0

非常感謝您的意見,我會給你的想法一個旋轉,看看我可以進步多遠。 – Attila66 2013-05-02 06:47:25

+0

哎呀,我只是重新讀你的問題,我以爲你的註冊點是左上角。同樣的邏輯適用,但將新剪輯的高度更改爲0,並檢查剪輯是否離屏,y等於(或更大)舞臺高度+對象高度。 – mitim 2013-05-02 07:29:16

+0

已添加檢查以確定mc的全部高度何時可見&'在舞臺上',以及mc的全高度是否不可見&'關閉舞臺'且兩個功能都正常。 我還添加了一個刪除子語句,這樣當mc變得不可見時,它將從舞臺上移除並返回到庫中。這以可視的方式工作(即mc從舞臺消失),但根據輸出結果,mc(儘管不可見)仍然存在並且在進一步超過可見的階段極限之後行進。 – Attila66 2013-05-04 03:59:33

0

管理這一個進一步進一步。

已添加檢查以確定MC的全高度何時可見&'在舞臺上'且MC的完整高度不可見時&'off stage'且兩個都正常工作。

我還添加了一個刪除子語句,這樣當mc變成不可見&後臺時,它將從舞臺上移除並返回到庫中。這以可視方式工作(即,mc從舞臺消失),但是,根據輸出結果,mc(雖然不可見)看起來仍然存在於進一步超過可見階段限制的地方。