2012-03-27 32 views
0

所以我有一個假預載器去...並不實際預載,但只是做'行動'。我的問題得到100%太快。由於它沒有真正加載任何東西,我如何減慢速度,所以它需要3秒「完成加載」?使假預載器移動得更慢

的代碼如下..

function onEnterFrame(){ 
// Calcules the max width value of the line 
maxWidth = _x*2; 

loaded = (_root.getBytesLoaded()/_root.getBytesTotal())*100; 

// Percentage to output on the percentage textbox 
per = Math.round(loaded) + "%"; 

// Clear this movieclip for drawing 
this.clear(); 

// Draw the white line: 
this.lineStyle(1,backLineColor,100); 
this.moveTo(0,0); 
this.lineTo(Math.abs(Stage.width-maxWidth),0); 

// Draws the black line 
this.lineStyle(1,frontLineColor,100); 
this.moveTo(0,0); 
this.lineTo(Math.abs((Stage.width-maxWidth)*(loaded/100)),0); 
+0

我在我的回覆中添加了假加載條的代碼,您可以測試。應該很容易嘗試。 – paul 2012-04-02 21:20:04

回答

0

它看起來像它實際上到主影片的負載反應,但(我猜),由當時的加載程序代碼實際運行電影有被加載,這就是爲什麼它如此之快。

如果你想假裝一個加載時間,建立一個計時器,每運行200毫秒左右運行一次,並在3秒後停止運行(使它沿途更新加載狀態)。

編輯:

這會幫助你建立一個間隔計時器 - 看到標題爲「要以間隔重複做一些事情」:

http://flash-creations.com/notes/actionscript_timersanddelays.php

(不要忘記清除當你完成它的計時器!)

或者,因爲你運行這個代碼每幀你可以使用文件的幀每秒作爲你的時間間隔,並做類似的事情:

fps = ... 

if (i * (1/fps) < 3) 
{ 
    loaded = (i * (1/fps))/3 * 100; 
    i++; 
} 

中的函數。

編輯:

這裏是它使用一個定時器以一個進度條,增長一些代碼。要運行它,只需創建一個新的Flash文件(ActionScript 2.0)並將其放入第一幀的操作中即可。

//////////////////////////////////////////////////////// 
// set up the properties of the load-bar 
//////////////////////////////////////////////////////// 

// set the width in pixels of the load bar 
// and the X and Y coordinates it should start at 
var loadBarWidth = 100; 
var loadBarX = 200; 
var loadBarY = 100; 


//////////////////////////////////////////////////////// 
// set-up a timer to fake loading of the movie clip 
//////////////////////////////////////////////////////// 

// set how often in milliseconds the timer should run 
var repetitionPeriod = 100; 
// set how long we want the timer to run (in milliseconds) 
var timerLength = 3000; // 3000 milliseconds = 3 seconds 
// varaible to hold how long we've been running 
var runTime = 0; 

// start the timer 
var intervalHandle = setInterval(_root, "intervalCallback", repetitionPeriod); 

// callback function to run every repetition period of the timer 
function intervalCallback() 
{ 
    // add the latest inverval to the total we've run 
    runTime += repetitionPeriod 

    // if we've run the full amount of time 
    // then stop the interval timer 
    if (runTime >= timerLength) 
    { 
     clearInterval(intervalHandle); 
    } 

    // update our load bar 
    // Percentage to output on the percentage textbox 
    //per = Math.round(loaded) + "%"; 

    // draw a line 
    this.lineStyle(1, frontLineColor); 
    this.setRGB(255,255,255); 
    this.moveTo(loadBarX,loadBarY); 
    this.lineTo(loadBarX + runTime/timerLength * loadBarWidth, loadBarY); 
} 
+0

你是我的精心製作嗎?我是小白。我在教程中找到了這段代碼,所以我不確定如何設置一個計時器。 – 2012-03-27 12:44:15

+0

你可能想刷新,我不得不更新數學,因爲我還沒有醒來。 – paul 2012-03-27 13:45:26

+0

感謝您的幫助。我檢查了鏈接,並嘗試了一些他們所說的話,但似乎無法得到它。 – 2012-03-27 13:48:58

1

好吧,坦白說,這不是一個假的預裝載機。

他們在教程網站給了你一個完美的原始和精心編碼的預加載器。

它快速移動的原因是因爲電影已經加載。如果尚未加載,您將能夠看到預加載器顯示加載的數量。

要查看預加載程序的外觀(即模擬加載操作),從Flash運行電影(Windows鍵盤快捷鍵爲Ctrl + Enter)時,請轉到查看>下載設置並選擇速度模擬下載。然後點擊「模擬下載」(或再次點擊Ctrl + Enter)。你會看到電影將如何加載到互聯網連接上。

P.S .:我很驚訝該教程沒有提到這個,因爲當我學習AS2時,我看了一個預加載器教程,它有幾乎相同的代碼,但也有這個解釋。

P.S. 2:爲什麼不學習AS3而不是(幾乎)過時的AS2?

+0

該網站已在幾年前做了as2,當我做到了。我不想切換到as3只是想添加preloader。我知道如何模擬下載看它是如何工作的,我只是想即使網站已經加載,預加載器的動畫也會出現3秒,因爲網站的加載速度非常快,它只是我想看到的一個功能 – 2012-03-31 19:08:33

+0

爲什麼?這違反了預加載程序的要點,無論如何,你可以在預加載器之後創建一個動畫(所以預加載器將結束並且該動畫將開始)。動畫持續3秒,然後顯示實際內容。 – 2012-04-01 04:23:38