如何从同一位置保持并继续 FOR-LOOP

发布于 2024-12-03 09:55:44 字数 952 浏览 1 评论 0原文

大家好,我有一个 for/foreach 循环,调用其中的函数。问题是被调用的函数在循环再次结束之前没有完成它的工作/

这是我的代码:

            private function ziv(result:Array,fail:Object):void
        {
            var i:uint = result.length;
            for each(var f:Object in result)
            {
                var item:Object = f;
                notfriend=item;
                FacebookDesktop.fqlQuery("SELECT uid1, uid2 FROM friend WHERE uid1 = me() AND uid2 = "+item.id,myfriends);

            }
        }

        private function myfriends(result:Object,fail:Object):void
        {
            if (result.length != 0)
            myfriend.addItem(notfriend);
        }

如您所见,我想在 MYFRIENDS 函数中添加一个项目(notfriend),“notfriend”在循环内定义,但是当“MYFRIENDS”函数完成加载时,该项目已经更改为下一个项目,即使我最初指的是上一个项目。 有没有办法可以保持 FORloop 直到“myfriends”函数完成加载。

我想在“myfriends”函数上使用事件监听器,但是我该怎么做才能停止\保持循环?我所知道的是 BREAK - 它破坏了 FOR-LOOP 和 CONTINUE - 它从下一个迭代继续循环。

10 倍很多,我真的在这里抓狂了!

Hi guys I got a for/foreach loop the calls a function inside of it. The prolem is that the function being-called doesnt fininsh it's job before the loop goes over again/

Here is my code:

            private function ziv(result:Array,fail:Object):void
        {
            var i:uint = result.length;
            for each(var f:Object in result)
            {
                var item:Object = f;
                notfriend=item;
                FacebookDesktop.fqlQuery("SELECT uid1, uid2 FROM friend WHERE uid1 = me() AND uid2 = "+item.id,myfriends);

            }
        }

        private function myfriends(result:Object,fail:Object):void
        {
            if (result.length != 0)
            myfriend.addItem(notfriend);
        }

As you can see i want to add an item (notfriend) in MYFRIENDS function, "notfriend" is defined inside the loop, but by the time "MYFRIENDS" function finish loading the item already changes to the next item even though i was originally refering to the previous item.
Is there a way to maybe hold the FORloop until "myfriends" function finish loading.

I wanted to use Eventlistener on "myfriends" function , but then what do i do to stop\hold the loop? all i know is BREAK-which destroyes the FOR-LOOP and CONTINUE-which continue the loop from the next iterate.

10x alot , im really braking my head here!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一刻暧昧 2024-12-10 09:55:44

也许看看不使用 for 循环并手动执行循环(下面的示例使用递归)

private var index=0;
private function processArray() {
  proccessArrayItem(array[index])
}
private function proccessArrayItem(obj) {

   //after complete then call function recursively
   index++;
   if (index<array.length) proccessArrayItem(array[index])
}

Maybe look at not using a for loop and do your loop manually (example below uses recursion)

ie

private var index=0;
private function processArray() {
  proccessArrayItem(array[index])
}
private function proccessArrayItem(obj) {

   //after complete then call function recursively
   index++;
   if (index<array.length) proccessArrayItem(array[index])
}
对你的占有欲 2024-12-10 09:55:44

您可以使用递归函数,

在某些情况下,

 private function setZoom():void
        {
            var zoomLevel:Number = new Number(myPanel);
            if(zoomLevel != 100)
            {
                if(zoomLevel < 100)
                {
                    myPanel.zoomIN();
                    setZoom();
                }
                else
                {
                    myPanel.zoomOUT();
                    setZoom();
                }
            }
        }

但在某些情况下,我们无法

通过

使用 定时器函数

setTimeout() 或 callLater();

U can use recursive function in some cases

like

 private function setZoom():void
        {
            var zoomLevel:Number = new Number(myPanel);
            if(zoomLevel != 100)
            {
                if(zoomLevel < 100)
                {
                    myPanel.zoomIN();
                    setZoom();
                }
                else
                {
                    myPanel.zoomOUT();
                    setZoom();
                }
            }
        }

but some cases we cant do that

by only one solution we can achieve by

using TimerFunctions

setTimeout() or callLater();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文