Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash 使假预加载程序移动较慢_Flash_Actionscript_Actionscript 2 - Fatal编程技术网

Flash 使假预加载程序移动较慢

Flash 使假预加载程序移动较慢,flash,actionscript,actionscript-2,Flash,Actionscript,Actionscript 2,所以我有一个假预载器。。。实际上不预加载,但只执行“操作”。我的问题是它达到100%的速度太快了。由于它实际上没有加载任何东西,我如何减慢速度,使其大约需要3秒钟才能完成加载 代码如下 function onEnterFrame(){ // Calcules the max width value of the line maxWidth = _x*2; loaded = (_root.getBytesLoaded()/_root.getBytesTotal())*100; // Perce

所以我有一个假预载器。。。实际上不预加载,但只执行“操作”。我的问题是它达到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);

它看起来确实对主电影的加载做出了反应,但我猜加载程序代码实际运行电影的时间已经加载,这就是为什么它运行得如此之快

如果您想伪造加载时间,请设置一个计时器,使其每隔200ms左右运行一次,并在3秒后停止运行,使其沿途更新加载状态

编辑:

这将有助于设置间隔计时器-请参阅标题为“以间隔重复执行某些操作”的部分:

完成计时器后,别忘了清除它

或者,由于您在每帧运行此代码,您可以使用文档每秒的帧数作为时间间隔,并执行以下操作:

fps = ...

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

好的,坦率地说,这不是一个假的预加载程序

他们在教程站点上为您提供了一个完全原创且编码良好的预加载程序

它移动速度快的原因是电影已经加载。如果没有加载,您将能够看到预加载程序显示加载量

要查看预加载程序的外观,即模拟加载操作,当您从Flash Windows运行电影时,键盘快捷键为Ctrl+Enter,请转到“查看”>“下载设置”,然后选择一个速度来模拟下载。然后单击Simulate Download或再次按Ctrl+Enter键。您将看到电影将如何在internet连接上加载

附言:我很惊讶教程没有提到这一点,因为当我学习AS2时,我看了一个预加载教程,它有几乎相同的代码,但也有这个解释


附言2:为什么不学习AS3而不是几乎过时的AS2呢?

你有详细阐述吗?我是诺布。我在教程中找到了这段代码,所以我不知道如何设置计时器。您可能需要刷新,因为我还没醒,我不得不更新了几次数学。谢谢您的帮助。我查看了链接,尝试了他们说的一些事情,但似乎没有得到它。我还尝试了你的代码,预加载程序只是冻结了lol。。我显然做错了什么。lolMy代码不完整,例如,您必须在函数外部初始化i。尝试查看函数的文档,因为这将有助于您了解函数的更好功能。我发布的链接上的例子可能是一个很好的开始,试着自己运行它,也许吧?几年前我做的时候,这个网站已经用as2制作了。我不想切换到as3只是想添加预加载程序。我知道如何模拟下载,看看它是如何工作的,我只是希望预加载程序的动画能够持续3秒钟,即使站点已经加载,因为站点加载速度非常快。这只是我想看的一个特性。为什么?这违背了预加载程序的观点。无论如何,您可以在预加载之后创建动画,以便预加载将结束,而此动画将开始。动画持续3秒钟,然后你显示你的实际内容。我在我的回复中添加了一个假加载条的代码,你可以测试它。这应该很容易尝试。
////////////////////////////////////////////////////////
// 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);
}