ADOBE/ ActionScript

Java에서 쓰는 데이터형(map, array)는 AS3.0에서 어떻게 쓰이나?

AlrepondTech 2011. 11. 14. 16:20
반응형

 

 

 

 

=================================

=================================

=================================

 

 

 

 

출처: http://nkdk.tistory.com/478

자바에서 효율적으로 쓰던 것이 map과Array가 있는데 AS3.0에도 그게 있나 찾아 봤더니 조금 다른 형태로 존재는 하네요 ^_^; 사용방법은 다음과 같다.

map의 경우
var obj : Object = new Object();
obj["키"] = 값;


array의 경우

1번
 var letters:Array = new Array();
 
 letters.push("a");
 letters.push("b");
 letters.push("c");
 
 trace(letters.toString()); // a,b,c
 trace(letters[0]); // a
 

2번

var letters:Array = new Array("a");
 var count:uint = letters.push("b", "c");
 
 trace(letters); // a,b,c
 trace(count);   // 3

이런식으로도 가능..

아 그리고 java에서 hashMap형태로 하는 방법도 있습니다. dictionary를 이용해서.. 소스는 다음과 같습니다.

package com.kkk
{
    import flash.utils.Dictionary;
   
  
    public final class HashMap
    {
       
        private var map:Dictionary;
       
       
        public function HashMap(useWeakReferences:Boolean = true)
        {
            map = new Dictionary( useWeakReferences );
        }

       
        public function put(key:*, value:*) : void
        {
            map[key] = value;
        }

       
        public function remove(key:*) : void
        {
            delete map[key];
        }

       
        public function containsKey(key:*) : Boolean
        {
            return map[key] != null;
        }

       
        public function containsValue(value:*) : Boolean
        {
            var result:Boolean;

            for ( var key:* in map )
            {
                if (map[key] == value)
                {
                    result = true;
                    break;
                }
            }
            return result;
        }

       
        public function getKey(value:*) : String
        {
            var id:String = null;

            for ( var key:* in map )
            {
                if (map[key] == value)
                {
                    id = key;
                    break;
                }
            }
            return id;
        }

       
        public function getKeys() : Array
        {
            var keys:Array = [];

            for (var key:* in map)
            {
                keys.push( key );
            }
            return keys;
        }

       
        public function getValue(key:*) : *
        {
            return map[key];
        }

       
        public function getValues() : Array
        {
            var values:Array = [];

            for (var key:* in map)
            {
                values.push( map[key] );
            }
            return values;
        }

       
        public function size() : int
        {
            var length:int = 0;

            for (var key:* in map)
            {
                length++;
            }
            return length;
        }

       
        public function isEmpty() : Boolean
        {
            return size() <= 0;
        }

       
        public function reset() : void
        {
            for ( var key:* in map )
            {
                map[key] = null;
            }
        }

       
        public function resetAllExcept(keyId:*) : void
        {
            for ( var key:* in map )
            {
                if ( key != keyId )
                {
                    map[key] = null;
                }
            }
        }

      
        public function clear() : void
        {
            for ( var key:* in map )
            {
                remove( key );
            }
        }

       
        public function clearAllExcept(keyId:*) : void
        {
            for ( var key:* in map )
            {
                if ( key != keyId )
                {
                    remove( key );
                }
            }
        }
    }
}

[출처] (FlexComponent) |작성자 swine777

 

=================================

=================================

=================================

 

 

 

반응형