'operator'에 해당되는 글 2건

  1. [2007/07/04] AS3.0 :: XML에 새롭게 추가된 @ (at sign) operator (13)
  2. [2007/06/18] The is operator and as operator (10)

AS3.0 :: XML에 새롭게 추가된 @ (at sign) operator

[FLASH/Reference]
The first example shows how to use the @ (at sign) operator to identify an attribute of an element:
var myXML:XML = 
<item id = "42">
<catalogName>Presta tube</catalogName>
<price>3.99</price>
</item>;

trace(myXML.@id); // 42
The next example returns all attribute names:
var xml:XML =<example id='123' color='blue'/>
var xml2:XMLList = xml.@*;
trace(xml2 is XMLList); // true
trace(xml2.length()); // 2
for (var i:int = 0; i < xml2.length(); i++)
{
trace(typeof(xml2[i])); // xml
trace(xml2[i].nodeKind()); // attribute
trace(xml2[i].name()); // id and color
}
The next example returns an attribute with a name that matches a reserved word in ActionScript. You cannot use the syntax xml.@class (since class is a reserved word in ActionScript). You need to use the syntax xml.attribute("class"):
var xml:XML = <example class='123'/>
trace(xml.attribute("class")); // 123

----------------------------------------------------------------------------

@ (at sign) 과 Dot Syntax 맘에 든다.
무작정 childNodes로 돌리고 대략 정의내려서 작업했던 시절은 가고~ 좀더 직접적인 접근방식의 XML로써 코드의 양을 상당 줄여주고 효율성을 높였다.
E4X(ECMAScript for XML)의 파워~

2007/07/04 13:38 2007/07/04 13:38

The is operator and as operator

[FLASH/Reference]
/*
is operator는 상속계층에 대한 비교를 해주는 연산자이다. return 값은 Boolean으로서 true or false 이다.
*/
var mc:MovieClip = new MovieClip();
//
trace (mc is MovieClip);// true
trace (mc is Sprite);// true
trace (mc is DisplayObject);// true
trace (mc is IEventDispatcher);// true

/*
여기서 is는 언듯 보면 instanceof 와 흡사하지만 아래와 같은 문제를 발생시킨다.
*/
trace (mc instanceof MovieClip); // true
trace (mc instanceof Sprite); // true
trace (mc instanceof DisplayObject); // true
trace (mc instanceof IEventDispatcher); // false

/*
as operator는 데이타 유형의 일원인지를 검사하는 것을 허용한다. is operator 와는 다르게 as operator는 부울 값을 돌려보내지 않고 데이타 유형을 return 한다.
*/
var mc1:MovieClip = new MovieClip();
//
trace (mc1 as MovieClip); // [object MovieClip]
trace (mc1 as Sprite); // [object MovieClip]
trace (mc1 as DisplayObject); // [object MovieClip]
trace (mc1 as IEventDispatcher); // [object MovieClip]
2007/06/18 10:34 2007/06/18 10:34