Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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 AS2到AS3时间函数_Flash_Class_Actionscript - Fatal编程技术网

Flash AS2到AS3时间函数

Flash AS2到AS3时间函数,flash,class,actionscript,Flash,Class,Actionscript,我通常在AS2代码上这样做 this.pause3Seconds = function () { trace(_global.something(_root.somthing)); clearInterval(myInt); }; var myInt = setInterval(this, "pause3Seconds", 3000); 现在,尝试将其转换为class.as文件时,会出现所有类型的迁移错误和警告 我来了。 有人知道如何在一个类中实

我通常在AS2代码上这样做

this.pause3Seconds = function () {
        trace(_global.something(_root.somthing));
        clearInterval(myInt);
    };
    var myInt = setInterval(this, "pause3Seconds", 3000);
现在,尝试将其转换为class.as文件时,会出现所有类型的迁移错误和警告

我来了。 有人知道如何在一个类中实现这一点吗

我不是按时间表工作的。(框架)

约翰


您的AS2代码实际上不会暂停播放器(
enterFrame
侦听器和鼠标/按键侦听器将在这三秒钟内执行)。它只是确保方法
pause3Seconds
将在三秒钟后调用。您可以使用
定时器
类在AS3中实现类似的功能

var timer:Timer = new Timer(3000, 1);
timer.addEventListener(TimerEvent.TIMER, onTimerTick);
function onTimerTick(e:TimerEvent = null):void
{
    if(e)
    {
        trace("3 seconds completed");
        Timer(e.target).removeEventListener(TimerEvent.TIMER, onTimerTick);
    }
}

@艾伦:这将使你的flash代码抛出运行时错误(脚本花费的时间比预期的要长)。在函数中睡觉总是个坏主意

@乔恩:这有点像“你的方式”解决方案:)

导入flash.utils.*//对于设置间隔和清除间隔
公共类YourClass{
私有变量myInt:uint;
公共函数YourClass():void{//YourClass是类的名称
myInt=setInterval(暂停3秒,3000);
}
公共函数pause3Seconds(){
跟踪(“3秒后你想要什么”);
clearInterval(myInt);
}
}


-bhups

谢谢您的回复。我还是有点困惑,玩家怎么知道我们会暂停这个功能多久?用暂停时间代替睡眠时间(3000)。因此,基本上,代码一直处于循环中,直到经过的时间超过3000毫秒,在这种情况下,您可以根据需要执行任何操作,然后代码就脱离了循环。顺便说一句,想要这个有什么用?应该避免像这样暂停播放器。在这样的循环中锁定代码可能会导致swf冻结和显示忙碌的光标。正如艾伦所说,尽量不要使用它。你可能会考虑重新设计。你的用例是什么?@Allan&Amarghosh。在我的swf结束时,我在2天内使用它的想法是,所以没有更多的事情发生!然后将最后的信息显示到swf中,并在3秒钟后退出swf。是的,我想知道这个,函数的名称让我相信他想要睡眠式暂停,但希望(从编码的角度)这是他们想要的。谢谢你的回复。你说得对,当我用这种方式的时候,我会一直确保框架上没有任何东西,没有按钮或者其他任何东西。这将迫使玩家等待3秒粘贴完毕。到那时为止,这是最好的解决方案,但不是正确的解决方案。使用此解决方案非常接近。唯一的问题是当函数调用时,我得到一个参数错误:参数错误:错误#1063:ontimertick()上的参数计数不匹配。应为:1,当前值为0。你知道吗?你的监听函数中没有所需的参数。很可能缺少e:TimerEventI我已经修改了方法签名,这样您就可以在不传递任何参数的情况下从代码的其他部分调用它。感谢您的回复,请尝试一下,并得到与上面相同的错误。错误#1063:pause3Seconds()上的参数计数不匹配。应为:1,当前值为0。在flash.utils::Timer/_timerDispatch()at flash.utils::Timer/tick()处的函数/at SetIntervalTimer/onTimer()有什么想法吗?谢谢john@bhups是的,因此我知道我的评论是不好的:)虽然3秒可能在脚本内花费的时间比预期的要长-您可以更改时间限制,aa并且有一种方法可以避免脚本错误;-)默认脚本时间限制为15秒。package{import flash.utils.*;//对于setInterval和clearInterval导入flash.display.Sprite;公共类YourClass扩展Sprite{private var myInt:uint;公共函数YourClass():void{//YourClass是类的名称myInt=setInterval(pause3Seconds,3000);}公共函数pause3Seconds(){trace(“3秒后你想要什么”);clearInterval(myInt);}}}我已经编译了这个函数,对我来说工作正常。我把你的课当作了一门课。试试这个,它应该会起作用。@Allan,@Amarghosh:在函数中睡觉肯定会打破flash运行时基于事件的想法,它只在需要时使用cpu,不会杀死浏览器。:)
var timer:Timer = new Timer(3000, 1);
timer.addEventListener(TimerEvent.TIMER, onTimerTick);
function onTimerTick(e:TimerEvent = null):void
{
    if(e)
    {
        trace("3 seconds completed");
        Timer(e.target).removeEventListener(TimerEvent.TIMER, onTimerTick);
    }
}