ArrayUtil class contains static utility methods for manipulating and working with Arrays. Note that all APIs assume that they are working with well formed arrays. I.e. they will only manipulate indexed values.

Methods:

1. arrayContainsValue():

public static arrayContainsValue(arr:Array,value:Object):Boolean

Parameters:

arr:Array The array that will be checked for specified value.

value:Object The object which will be searched for within the array.

Returns:

Boolean True if the array contains the value, False if it does not.

2. arraysAreEqual()

public static function arraysAreEqual(arr1:Array, arr2:Array):Boolean

Compares two arrays and returns a boolean indicating whether the arrays contain the same values at the same indexes.

Parameters:

arr1:Array The first array that will be compared to the second.

Arr2:Array The second array that will be compared to the first.

Returns:

Boolean True if the arrays contains the same values at the same indexes.

False if they do not.

3. copyArray():

public static function copyArray(arr:Array):Array

Creates a copy of the specified array. Note that the array returned is a new array but the items within the array are not copies of the items in the original array (but rather references to the same items).

Parameters:

arr:Array The array that will be copies

Returns:

Array A new array which contains the same items as the array passed in.

4. createUniqueCopy()

public static function createUniqueCopy(a:Array):Array

Create a new array that only contains unique instances of objects in the specified array. Basically, this can be used to remove duplication object instances from an array

Parameters:

a:Array The array which contains the values that will be used to create the new array that contains no duplicate values.

Returns:

Array A new array which only contains unique items from the specified array.

5. removeValueFromArray()

public static function removeValueFromArray(arr:Array, value:Object):void

Remove all instances of the specified value from the array.

Parameters:

arr:Array — The array from which the value will be removed.

value:Object — The object that will be removed from the array.

Screenshot:

In this demo, “array1” is the same as “array2” and a little different with “array3”, the order of their elements is different.

Enter any value of the elements of array1 into the input box contained in the row which owns button “arrayContainsValue”. Then, click the button, a dialog pop up to show the result whether the element with the input value is contained in array1.

“arraysAreEqual” compares “array1” with “array2” and “array1” with “array3”.

“copyArray” copy “array1”and add a new TextInput to show the copied array.

“createUniqueArray” is similar as “copyArray”. But its elements are unique.

Enter the value of elements in Array1 into the input box beside “removeValueFromArray”, then, click the button to implement the method.

The element with value “5” is remove from array1.

The following is full source code

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
import com.adobe.utils.ArrayUtil;
import mx.controls.Alert;
[Bindable]
private var array1:Array = [1,2,3,4,5,6,7,8,9,10,11,22,22,33,34,34];
[Bindable]
private var array2:Array = [1,2,3,4,5,6,7,8,9,10,11,22,22,33,34,34];
[Bindable]
private var array3:Array = [1,2,3,4,5,6,7,8,9,10,22,11,22,34,33,34]; private var array:Array = [array1,array2,array3]; private function doArrayContainsValue():void
{
var msg:String = "does array1 contains value "+containedValue.text+"?";
msg += "\n"; msg += ArrayUtil.arrayContainsValue(array1,int(containedValue.text))?"yes":"no"; Alert.show(msg);
} private function doArraysAreEqual():void
{ var msg:String = "does array1 equals array2 ?";
msg += "\n";
msg += ArrayUtil.arraysAreEqual(array1,array2)?"yes":"no"; msg += "\n"; msg += "does array1 equals array3 ?";
msg += "\n";
msg += ArrayUtil.arraysAreEqual(array1,array3)?"yes":"no"; Alert.show(msg);
} private function doCopyArray():void
{
var newArray:TextInput = new TextInput();
newArray.editable = false;
newArray.percentWidth = 100; var copiedArray:Array = ArrayUtil.copyArray(array1);
newArray.text = "array"+ String((array.length+1))+ ":" + copiedArray.toString() + " copied from array1";
array.push(copiedArray); container.addChild(newArray); container.validateNow();
} private function doUniqueCopy():void
{
var newArray:TextInput = new TextInput();
newArray.editable = false;
newArray.percentWidth = 100; var copiedArray:Array = ArrayUtil.createUniqueCopy(array1);
newArray.text = "array"+ String((array.length+1))+ ":" + copiedArray.toString() + " copied from array1";
array.push(copiedArray); container.addChild(newArray); container.validateNow();
} private function doRemoveValueFromArray():void
{
if(ArrayUtil.arrayContainsValue(array1,int(removedValue.text)))
{
ArrayUtil.removeValueFromArray(array1,int(removedValue.text));
array1Text.text = "array1:"+ array1.toString();
}
else
{
var msg:String = "array1 does not contain value "+removedValue.text;
}
}
]]>
</mx:Script>
<mx:VBox id="container" width="100%" height="100%">
<mx:TextInput id="array1Text" editable="false" text="array1:{ array1.toString()}" width="100%"/>
<mx:TextInput editable="false" text="array2:{ array2.toString()}" width="100%"/>
<mx:TextInput editable="false" text="array3:{ array3.toString()}" width="100%"/>
<mx:HBox>
<mx:Label text="does array1 contains value:"/>
<mx:TextInput id="containedValue" text="5"/>
<mx:Button label="arrayContainsValue" click="doArrayContainsValue();"/>
</mx:HBox>
<mx:HBox>
<mx:Button label="arraysAreEqual" click="doArraysAreEqual();"/>
</mx:HBox>
<mx:HBox>
<mx:Button label="copyArray" click="doCopyArray();"/>
</mx:HBox>
<mx:HBox>
<mx:Button label="createUniqueCopy" click="doUniqueCopy();"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="remove value"/>
<mx:TextInput id="removedValue" text="5"/>
<mx:Button label="removeValueFromArray" click="doRemoveValueFromArray();"/>
</mx:HBox>
</mx:VBox>
</mx:Application>

最新项目地址: https://github.com/mikechambers/as3corelib

转自: http://ntt.cc/2008/09/01/as3corelib-tutorial-how-to-use-arrayutil-class-in-flex.html

as3corelib Tutorial:How to Use ArrayUtil Class in Flex的更多相关文章

  1. [翻译+山寨]Hangfire Highlighter Tutorial

    前言 Hangfire是一个开源且商业免费使用的工具函数库.可以让你非常容易地在ASP.NET应用(也可以不在ASP.NET应用)中执行多种类型的后台任务,而无需自行定制开发和管理基于Windows ...

  2. Django 1.7 Tutorial 学习笔记

    官方教程在这里 : Here 写在前面的废话:)) 以前学习新东西,第一想到的是找本入门教程,按照书上做一遍.现在看了各种网上的入门教程后,我觉得还是看官方Tutorial靠谱.书的弊端一说一大推 本 ...

  3. thrift 服务端linux C ++ 与客户端 windows python 环境配置(thrift 自带tutorial为例)

    关于Thrift文档化的确是做的不好.摸索了很久才终于把跨linux与windows跨C++与python语言的配置成功完成.以下是步骤: 1)                 Linux下环境配置 ...

  4. Hive Tutorial(上)(Hive 入门指导)

    用户指导 Hive 指导 Hive指导 概念 Hive是什么 Hive不是什么 获得和开始 数据单元 类型系统 内置操作符和方法 语言性能 用法和例子(在<下>里面) 概念 Hive是什么 ...

  5. Home / Python MySQL Tutorial / Calling MySQL Stored Procedures in Python Calling MySQL Stored Procedures in Python

    f you are not familiar with MySQL stored procedures or want to review it as a refresher, you can fol ...

  6. Using FreeMarker templates (FTL)- Tutorial

    Lars Vogel, (c) 2012, 2016 vogella GmbHVersion 1.4,06.10.2016 Table of Contents 1. Introduction to F ...

  7. Oracle Forms 10g Tutorial Ebook Download - Oracle Forms Blog

    A step by step tutorial for Oracle Forms 10g development. This guide is helpful for freshers in Orac ...

  8. Tutorial - Deferred Rendering Shadow Mapping 转

    http://www.codinglabs.net/tutorial_opengl_deferred_rendering_shadow_mapping.aspx Tutorial - Deferred ...

  9. anguar.js tutorial demo

    http://docs.angularjs.cn/tutorial angular 入门demo : PhoneCat Tutorial App 别人的DEMO(官方版):http://angular ...

随机推荐

  1. 批量部署Hadoop集群环境(1)

    批量部署Hadoop集群环境(1) 1. 项目简介: 前言:云火的一塌糊涂,加上自大二就跟随一位教授做大数据项目,所以很早就产生了兴趣,随着知识的积累,虚拟机已经不能满足了,这次在服务器上以生产环境来 ...

  2. PHP memcache扩展安装 for Windows

    一.下载并安装memcached服务器端软件    1.下载memcached软件 32位下载地址: memcached-win32-1.4.4-14.zip(直接下载),memcached-win3 ...

  3. Git理论知识补充

    转自: http://www.cnblogs.com/hnrainll/archive/2012/11/13/2768003.html 对于任何一个文件,在 Git 内都只有三种状态:已提交(comm ...

  4. SEO 第八章

    SEO第八章 本次课目标: 1.  网站外部优化的外链优化 2.  网站流量分析 1.  什么叫做外链? 外链也叫反向链接,指的是从别的网站指向我自己的网站的链接. 2.  外链的作用? l  外链可 ...

  5. Microsoft Project 2010基础使用方法

    5.1 项目管理与Microsoft Project2010 Microsoft Project2010深受广大项目管理工程师的青睐. 5.1.1 项目管理的概念 项目管理是项目管理者在有限的资源约束 ...

  6. Qt_为什么学习Qt

    1)学习GUI编程,市场上任何一款产品几乎都带有图形界面,市场上很火的Androoid.IOS编程无非也是GUI app编程,GUI编程都是差不多的,学习Qt后再学习ANdroid IOS ,那都是S ...

  7. python爬虫---从零开始(一)初识爬虫

    我们开始来谈谈python的爬虫. 1,什么是爬虫: 网络爬虫是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本.另外一些不常使用的名字还有蚂蚁.自动索引.模拟程序或者蠕虫.互联网犹如一个大蜘蛛 ...

  8. java 数据库

    1.数据的概述 数据(data)是事实或观察的结果,是对客观事物的逻辑归纳,是用于表示客观事物的未经加工的的原始素材. 数据是信息的表现形式和载体,可以是符号.文字.数字.语音.图像.视频等.数据和信 ...

  9. 使用VS自带WCF测试客户端

    打开VS自带WCF测试客户端 打开VS2015 开发人员命令提示 输入:wcftestclient,回车 提取wcftestclient 当然,可以看到VS2015 开发人员命令提示知道,当前路径在C ...

  10. dubbo负载均衡策略和集群容错策略

    dubbo负载均衡策略 random loadbalance 默认情况下,dubbo是random load balance随机调用实现负载均衡,可以对provider不同实例设置不同的权重,会按照权 ...