【问题标题】:Does Flex 3 support threading?Flex 3 是否支持线程?
【发布时间】:2011-08-03 16:46:40
【问题描述】:

Flex 3 是否支持线程?如果是这样,我可以查看任何示例或链接吗?

【问题讨论】:

    标签: actionscript-3 apache-flex flex3


    【解决方案1】:

    正如 Alex here 所说:

    Actionscript 是单线程的,如果你花很多时间做繁重的工作 计算时,UI 无法在您执行此操作时更新 计算,因此您的应用程序似乎卡住或效果不运行 顺利。

    同样,Actionscript 中也没有让步或阻塞。如果 下一行代码应该运行,你不能阻止下一行 运行的代码行。这意味着当你调用 Alert.show() 时, 紧随其后的下一行代码立即运行。

    在许多其他运行时中,警报窗口必须在 下一行代码继续。线程可能是 Actionscript 总有一天,但在那之前,你必须接受这个事实 现在没有这样的东西。

    【讨论】:

      【解决方案2】:

      ActionScript 3 是单线程的。

      您可以做的是将工作切成足够小的切片,以免响应性受到太大影响。例如:

      private var _long_process_work_object:LongProcessWorkClass;
      private var _long_process_timer:Timer;
      
      private function startSomeLongAndIntensiveWork():void
      {
          _long_process_work_object = new LongProcessWorkClass();
      
          _long_process_timer = new Timer(10);
          _long_process_timer.addEventListener("timer", longProcessTimerHandler);
          _long_process_timer.start();
      }
      
      private function longProcessTimerHandler(event:TimerEvent):void 
      {
          _long_process_timer.stop();
      
          // do the next slice of work:
          // you'll want to calibrate how much work a slice contains to maximize 
          // performance while not affecting responsiveness excessively
          _long_process_work_object.doSomeOfTheWork();
      
          if (!_long_process_work_object.Done) {
              // long process is not done, start timer again
              _long_process_timer.start();
              return;
          }
      
          // long process work is done, do whatever comes after
      }
      

      【讨论】:

        【解决方案3】:

        在 Adob​​e 的某个地方,Flash Player 确实支持多线程...http://www.bytearray.org/?p=3007。它只是尚未公开。

        除此之外,请参阅 Multithreading or green threading in actionscript? 互联网上还有一个 few articles 介绍使用 Pixel Bender 的多线程进行数据处理。

        【讨论】:

          【解决方案4】:

          Flex 3 基于 ActionScript 3。ActionScript 3 不提供对多线程的支持(您不能编写针对多线程执行的代码)。 已编译的 flex 应用程序在 Flash Player 平台上运行。 Adobe Flash Player 11.4 及更高版本增加了对多线程的支持。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2019-12-27
            • 1970-01-01
            • 1970-01-01
            • 2018-05-29
            • 1970-01-01
            • 2022-10-14
            • 2020-02-21
            相关资源
            最近更新 更多