加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex中多线程的实现 (转)

发布时间:2020-12-15 01:14:30 所属栏目:百科 来源:网络整理
导读:最近在网上看到一个工具类可以提供flex中多线程的支持,AsyncThreading,googleCode地址,详细文档可以去googleCode上看? 下面总结一下利用这个工具类来实现一个抽奖机的demo。 首先我们要编写一个自定义线程类,继承自AbstractAsyncThread并且实现IAsyncThr
最近在网上看到一个工具类可以提供flex中多线程的支持,AsyncThreading,googleCode地址,详细文档可以去googleCode上看?
下面总结一下利用这个工具类来实现一个抽奖机的demo。
首先我们要编写一个自定义线程类,继承自AbstractAsyncThread并且实现IAsyncThreadResponder接口,
AbstractAsyncThread这个类可以控制线程的级别:
 ?? ? ? ? ? ? ? ?public const RUN_LEVEL_REAL_TIME:int = 1;
? ? ? ? ? ? ? ? public const RUN_LEVEL_HIGH:int = 3;
? ? ? ? ? ? ? ? public const RUN_LEVEL_ABOVE_NORMAL:int = 6:
? ? ? ? ? ? ? ? public const RUN_LEVEL_NORMAL:int = 8;
? ? ? ? ? ? ? ? public const RUN_LEVEL_BELOW_NORMAL:int = 12:
? ? ? ? ? ? ? ? public const RUN_LEVEL_LOW:int = 24; ?

IAsyncThreadResponder这个接口提供了一个线程启动后调用的方法
 ?? ? ? ? ? ? ? ?function execute():void; 

自定义线程对象类代码如下:
 package threads
{
? ? ? ? import cn.ningyu.utils.Random;
? ? ? ?
? ? ? ? import com.symantec.premiumServices.asyncThreading.abstract.AbstractAsyncThread;
? ? ? ? import com.symantec.premiumServices.asyncThreading.interfaces.IAsyncThreadResponder;
? ? ? ?
? ? ? ? import mx.controls.Label;
? ? ? ? public class WorkBee extends AbstractAsyncThread implements IAsyncThreadResponder
? ? ? ? {
? ? ? ? ? ? ? ? private var _lab:Label;
? ? ? ? ? ? ? ? public function WorkBee(lab:Label)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? _lab = lab;
? ? ? ? ? ? ? ? ? ? ? ? super();
? ? ? ? ? ? ? ? ? ? ? ? super.priority = super.RUN_LEVEL_REAL_TIME;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? public function execute():void
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? var random:Random = Random.getInstance();
? ? ? ? ? ? ? ? ? ? ? ? random.digit = 1;
? ? ? ? ? ? ? ? ? ? ? ? random.radix = Random.NUMBER;
? ? ? ? ? ? ? ? ? ? ? ? _lab.text = random.createRandom();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ?
? ? ? ? }
}

application中代码如下:
 <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
? ? ? ?
? ? ? ? <mx:Script>
? ? ? ? ? ? ? ? <![CDATA[
? ? ? ? ? ? ? ? ? ? ? ? import threads.WorkBee;
? ? ? ? ? ? ? ? ? ? ? ? import com.symantec.premiumServices.asyncThreading.AsyncThreadingManager;
? ? ? ? ? ? ? ? ? ? ? ? import mx.collections.ArrayCollection;
? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? private var threadList:ArrayCollection = new ArrayCollection();
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? private function init():void {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? threadList = new ArrayCollection();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? for(var i:int=0;i<7;i++) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? var workBee:WorkBee;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? switch(i) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case 0:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? workBee = new WorkBee(lab1);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读