티스토리 뷰

전에 올렸던예문[ FLEX ] XML 화일을 읽어와 MenuBar 에 바인딩"의  XML파일 동적 로드에서 발생했던 문제를 해결하는 방법은 URLLoader 을 이용하는것!

 

[MXML] 일부분... xml 파일도 동일함!

 

	import mx.collections.XMLListCollection;
	import mx.controls.Alert;
	import mx.events.MenuEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	
	[Bindable]
	public var xmlListColl:XMLListCollection;
	private function fn_iniApp():void
	{
		var urlLdr:URLLoader = new URLLoader();
		urlLdr.addEventListener(Event.COMPLETE,resultEvent);
		urlLdr.load(new URLRequest('http://127.0.0.1/kmec_config/x_test_XML.xml'));
	}
	private function resultEvent(evt:Event):void
	{
		var xmlData:XML = new XML(URLLoader(evt.currentTarget).data);
		xmlListColl = new XMLListCollection(xmlData.children());
	}
	protected function menubar1_itemClickHandler(event:MenuEvent):void
	{
		// TODO Auto-generated method stub
		if (event.item.@data != "top") {
			Alert.show("Label: " + event.item.@label + "\n" + 
			"Data: " + event.item.@data, "Clicked menu item");
		}        
	}

 

...

...

  

<mx:MenuBar x="24" y="27" width="299"
    labelField="@label"
    dataProvider="{xmlListColl}"
    itemClick="menubar1_itemClickHandler(event)">

</mx:MenuBar>

...