This page was saved using jaction on 2006-09-04 8:33:54.
Address: http://flexdocs.kr/docs/flex2/langref/Namespace.html
Title: Namespace (Flex™ 2 레퍼런스 가이드)  •  Size: 36533
Package톱 레벨
Classpublic final class Namespace
InheritanceNamespace Inheritance Object

Namespace 클래스에는, namespace를 정의해 조작하기 위한 Methods와 property가 포함되어 있습니다. namespace를 사용하는 시나리오에는, 다음의 3 개가 있습니다.

이 클래스는, 2 개의 형식의 constructor    Methods를 나타내고 있습니다. 각각의 형식이 다른 Parameters를 받아들이기 (위해)때문에입니다.

XML, XMLList, 및 QName 등의 클래스 같이, Namespace 클래스에는, ECMAScript for XML (E4X) 사양 (ECMA-357 Edition 2)으로 정의되고 있는 강력한 XML 처리 규격이 Implements되고 있습니다.

View the examples

See also

XML
XMLList
QName
ECMAScript for XML (E4X) specification (ECMA-357 edition 2)
XML namespace의 사용


Public property
 property정의
 Inheritedconstructor : Object
특정의 object 인스턴스의 클래스 object 또는 constructor    함수에의 참조입니다.
Object
  prefix : String
namespace의 접두사입니다.
Namespace
 Inheritedprototype : Object
[static] 클래스 또는 함수 object의 prototype object에의 참조입니다.
Object
  uri : String
namespace의 URI 입니다.
Namespace
Public Methods
 Methods정의
  Namespace (uriValue:* )
Namespace object를 작성합니다.
Namespace
  Namespace (prefixValue:* , uriValue:* )
prefixValue Parameters와 uriValue Parameters의 값에 따라 Namespace object를 작성합니다.
Namespace
 InheritedhasOwnProperty (name:String ):Boolean
object로 지정된 property가 정의되고 있는지 어떤지를 나타냅니다.
Object
 InheritedisPrototypeOf (theClass:Object ):Boolean
Object 클래스의 인스턴스가, Parameters로서 지정된 object의 prototype 체인내에 있을지 어떨지를 나타냅니다.
Object
 InheritedpropertyIsEnumerable (name:String ):Boolean
지정된 property가 존재해, 열거 가능한가 어떤가를 나타냅니다.
Object
 InheritedsetPropertyIsEnumerable (name:String , isEnum:Boolean = true):void
루프 처리에 대한 다이나믹 property의 가용성을 설정합니다.
Object
  toString ():String
Namespace.uri property와 동등합니다.
Namespace
  valueOf ():String
지정된 object의 URI 값를 돌려줍니다.
Namespace
property의 상세
prefixproperty
prefix:String   [read-write]

namespace의 접두사입니다.

Implements
    public function get prefix():String
    public function set prefix(value:String ):void
uriproperty 
uri:String   [read-write]

namespace의 URI 입니다.

Implements
    public function get uri():String
    public function set uri(value:String ):void
constructor    의 상세
Namespace()constructor   
public 함수 Namespace(uriValue:* )

Namespace object를 작성합니다. 새로운 Namespace object의 uri property와 prefix property에 할당할 수 있는 값은,uriValue Parameters에게 건네지는 값의 형태에 의해 정해집니다.

메모:이 클래스는, 2 개의 constructor    항목을 나타내고 있습니다. 각각의 형식이 다른 Parameters를 받아들이기 (위해)때문에입니다. constructor    의 동작은, 각 항목으로 상세를 나타내도록(듯이), 건네받는 Parameters의 형태와 수에 따라서 다릅니다. ActionScript 3.0 은 Methods 또는 constructor    의 overload를 지원(support)하고 있습니다.

Parameters
uriValue:* — namespace의 URI 입니다.
Namespace()constructor    
public 함수 Namespace(prefixValue:* , uriValue:* )

prefixValue Parameters와 uriValue Parameters의 값에 따라 Namespace object를 작성합니다. 이 constructor    에는 양쪽 모두의 Parameters가 필요합니다.

prefixValue Parameters의 값은, 다음과 같이 prefix property에 할당할 수 있습니다.

uriValue Parameters의 값은, 다음과 같이 uri property에 할당할 수 있습니다.

메모:이 클래스는, 2 개의 constructor    Methods를 나타내고 있습니다. 각각의 형식이 다른 Parameters를 받아들이기 (위해)때문에입니다. constructor    의 동작은, 각 항목으로 상세를 나타내도록(듯이), 건네받는 인수의 형태와 수에 따라서 다릅니다. ActionScript 3.0 은 Methods 또는 constructor    의 overload를 지원(support)하고 있습니다.

Parameters
prefixValue:* — namespace에 사용하는 접두사입니다.
 
uriValue:* — namespace의 URI 입니다.
Methods의 상세
toString()Methods
AS3 function toString():String

Namespace.uri property와 동등합니다.

반환값
String — string로서의 namespace의 URI 입니다.
valueOf()Methods 
AS3 function valueOf():String

지정된 object의 URI 값를 돌려줍니다.

반환값
String — string로서의 namespace의 URI 입니다.
Examples

다음의 예는, XML object에 정의되고 있는 namespace를 조작하는 방법을 나타내고 있습니다. 이것을 실시하려면 , 이하의 순서를 실행합니다.
  1. 이 예에서는 3 개의 Namespace object를 정의합니다. 각 object에는, namespace를 정의하는 일의의 URI 를 관련짓습니다.
  2. myXML 라는 이름의 XML 변수를 정의해, 이것을getRSS() 의 반환값에 할당합니다. getRSS() Methods는, 몇개의 namespace를 가지는 XML object를 정의해, 이 XML object를 돌려줍니다.
  3. myXML 를 건네주어 parseRSS() Methods를 호출하는 것에 의해, Array 변수를 선언해 평가합니다. parseRSS() 에서는, 디폴트의 XML namespace으로서 rss 가 정의되어 XMLList 변수가,myXML 내의 item object의 일람을 할당하는 것에 의해 정의됩니다. 배열이 작성되어 myXML.item내의 다양한 노드가 값으로 해서 설정됩니다. 그 후, 배열이 돌려주어집니다.
  4. for 루프를 사용해 trace().
package {
    import flash.display.Sprite;

    public class NamespaceExample extends Sprite {
        private var rss:Namespace = new Namespace("http://purl.org/rss/1. 0/");
        private var rdf:Namespace = new Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
        private var dc:Namespace  = new Namespace("http://purl.org/dc/elements/1. 1/");

        public function NamespaceExample() {
            var myXML:XML = getRSS();
            var rssItems:Array = parseRSS(myXML);
            
            var len:uint = rssItems.length;
            for (var i:uint; i < len; i++) {
                trace(rssItems[i]. title);
                trace(rssItems[i]. creator);
                trace(rssItems[i]. date);
                // Adobe Flash Developer Center
                // Adobe
                // 2005-08-08
                // Flex Developer Center
                // Adobe
                // 2005-10-16                
            }
        }
        
        private function parseRSS(rssXML:XML) :Array {
            default xml namespace = rss;

            var items:XMLList = rssXML.item;

            var arr:Array = new Array();            
            var len:uint = items.length();
            for (var i:uint; i < len; i++) {
                arr.push({title:items[i]. title, creator:items[i]. dc::creator, date:items[i]. dc::date});
            }
            
            return arr;
        }

        private function getRSS() :XML {
            var myXML:XML =  <rdf:RDF
              xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
              xmlns="http://purl.org/rss/1. 0/"
              xmlns:dc="http://purl.org/dc/elements/1. 1/"
            >
              <channel rdf:about="http://www.xml.com/cs/xml/query/q/19">
                <title>Test RSS</title>
                <link>http://www.adobe.com/</link>
                <description>This is a test RSS document. </description>
                <language>en-us</language>
                <items>
                  <rdf:Seq>
                <rdf:li rdf:resource="http://www.adobe.com/devnet/flash/"/>
                <rdf:li rdf:resource="http://www.adobe.com/devnet/flex/"/>
                  </rdf:Seq>
                </items>
              </channel>
              <item rdf:about="http://www.adobe.com/devnet/flash/">
                <title>Adobe Flash Developer Center</title>
                <link>http://www.adobe.com/devnet/flash/</link>
                <description>Welcome to the Flash Developer Center</description>
                <dc:creator>Adobe</dc:creator>
                <dc:date>2005-08-08</dc:date>    
              </item>
              <item rdf:about="http://www.adobe.com/devnet/flex/">
                <title>Flex Developer Center</title>
                <link>http://www.adobe.com/devnet/flex/</link>
                <description>Welcome to the Flex Developer Center</description>
                <dc:creator>Adobe</dc:creator>
                <dc:date>2005-10-16</dc:date>    
              </item>
            </rdf:RDF>;
            
            return myXML;
        }
    }
}

다음의 예는, namespace를 사용해, 이름이 같아도 실행하는 태스크가 다르다 Methods를 구별하는 방법을 나타내고 있습니다. 이 예에서는,hello() 라는 이름의 3 개의 Methods가 다른 namespace에 존재하고 있어, 불려 갔을 때에 각각이 다른 string를 돌려줍니다.
package {

    import flash.display.Sprite;

    public class Namespace_2_Example extends Sprite {    
        public function Namespace_2_Example() {
            var vocab:MultilingualVocabulary = new MultilingualVocabulary();

            trace(vocab.hello());    // hello
            
            var languages:Array = vocab.getLanguages();
            
            for (var i:uint; i < languages.length; i++) {
                var ns:Namespace = languages[i];
                if (ns ! = null) {
                    trace(ns.toString() + ": " + vocab.ns::hello());
                    // hello
                    // MultilingualVocabulary:Hawaiian: aloha
                    // MultilingualVocabulary:French: bon jour
                }
            }
        }
    }    
}

class MultilingualVocabulary {
    public namespace French;
    public namespace Hawaiian;
    private var languages:Array;

    public function MultilingualVocabulary() {
        languages = new Array(Hawaiian, French);
    }
        
    public function hello() :String { 
        return "hello";
    }

    Hawaiian function hello() :String {
        return "aloha";
    }

    French function hello() :String { 
        return "bon jour";
    }
        
    public function getLanguages() :Array {
        return languages;
    }
}

다음의 예는, namespace명을 사용해, 적절한 변수치를 선택하고 있습니다. 이 예는, namespace의 값을 변수에 포함해, 그 변수를 사용해 그 namespace내의 object를 참조하는 방법을 나타내고 있습니다.

이 예는, 직사각형의 버튼에 대한 마우스 상태에 대응한다 namespace과 색을 정의합니다. 버튼이 묘화 될 때마다, 대응하는 namespace (out,over,down)의 bgcolor 변수를 참조하는 것에 의해, 적절한 색 (마우스가 놓여지지 않을 때는 빨강, 마우스가 위에 놓여져 있는 상태에서는 황색, mouse button가 밀리고 있는 상태에서는 흰색)이 적용됩니다.

package {
    import flash.display.Sprite;
  
    public class Namespace_3_Example extends Sprite {     
        public function Namespace_3_Example() {
            addChild(new StateButton("Press Me. "));
        }
    }
}

import flash.display.Sprite;
import flash.text.TextField;
import flash.events.Event;
import flash.events.MouseEvent;

class StateButton extends Sprite{
    private namespace out;
    private namespace over;
    private namespace down;
    private var label:TextField;
    private var labelTxt:String;
    private var ns:Namespace;
    out var bgColor:Number = 0xFF0000;
    over var bgColor:Number = 0xFFFF00;
    down var bgColor:Number = 0xFFFFFF;
      
    public function StateButton(str:String) {
        buttonMode = true;
        labelTxt = str;
        ns = out;
        draw();
        addLabel();
        addListeners();
    }

    private function addLabel() :void {
        label = new TextField();
        label.text = labelTxt;
        label.width = 50;
        label.height = 20;
        label.mouseEnabled = false;
        addChild(label);
    }
      
    private function addListeners() :void {
        addEventListener(MouseEvent.MOUSE_UP, mouseOverHandler);
        addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
        addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
        addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    }
 
    private function mouseOutHandler(e:Event) :void {
        ns = out;
        draw();
    }
 
    private function mouseOverHandler(e:Event) :void {
        ns = over;
        draw();
    }
 
    private function mouseDownHandler(e:Event) :void {
        ns = down;
        draw();
    }
 
    private function draw() :void {
        this.graphics.clear();
        this.graphics.beginFill(ns::bgColor);
        this.graphics.drawRect(0, 0, 60, 20);
    }
}






 

코멘트가 추가되었을 경우, 메일로 받기. | 코멘트 리포트

현재의 페이지: http://flexdocs.kr/docs/flex2/langref/Namespace.html