ArrayCollectionã§é åã®å¤æ´ãæ¤ç¥ãããµã³ãã«
mx.collections.ArrayCollectionã使ãã¨é åã®å¤æ´ãã¤ãã³ããªã¹ãã¼ã®ä»çµã¿ã§æ¤ç¥ãããã¨ãã§ãã¾ãã
- ã³ã³ã¹ãã©ã¯ã¿ã§ã½ã¼ã¹ã¨ãªãé åãæå®ãã¦ArrayCollectionãä½æãã
- ã¤ãã³ããªã¹ãã¼ãè¨å®ããä¸ã§ã
- ArrayCollectionã®APIãå¼ã³åºãã¦é
åãæ´æ°ããã¨ãã¤ãã³ããéç¥ããã¾ãã
- ãã ããã³ã³ã¹ãã©ã¯ã¿ã§æå®ããé åãç´æ¥ç·¨éããã¨éç¥ã¯ãããªãã®ã§æ³¨æã
// çµæã®è¡¨ç¤ºç¨ var stdout:TextField = new TextField(); stdout.width = 500; stdout.height = 500; addChild(stdout); stdout.text = ""; // ArrayCollectionãä½æãå¼æ°ã§ã½ã¼ã¹ã¨ãªãé åã渡ãã var array:ArrayCollection = new ArrayCollection([1,2,3,4,5]); // ãªã¹ãã®æ´æ°ãªã¹ããè¨å® array.addEventListener( CollectionEvent.COLLECTION_CHANGE, function(ev:CollectionEvent):void{ stdout.text += <b>kind: {ev.kind} / items: {ev.items} / index: {ev.location}</b>.toString(); stdout.text += "\n"; }); // å¤ã®è¨å® / åå¾ for (var i:int=0; i < array.length; i++ ) { stdout.text += array.getItemAt(i) + ", "; // èªã¿è¾¼ã¿ } stdout.text += "\n"; array.setItemAt(9, 2); // è¨å® array.addItem(6); // 追å array.removeItemAt(4); // åé¤
実行結果はこちらããªããå®è¡ããæä½ã«å¿ãã¦ãevent.itemsãã®å¤ã¯å¤ããã¾ãã詳細ã¯CollectionEvent#itemãåç §ã
Proxyã使ã£ã¦ãã§ãããã©ãããã£ã¨ä½¿ãããå ´åã«ä¾¿å©ã§ããªã