Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function onCreationComplete(event:FlexEvent):void{
- app = S4M(this.parentApplication);
- var service:HTTPService;
- loadSubsymbols();
- // *************************************************
- // generateRequest
- // *************************************************
- function loadSubsymbols():void {
- service = new HTTPService();
- var action_url:String = "subsymbols.json";
- service.url = api_url + action_url;
- service.method = "GET";
- service.addEventListener(ResultEvent.RESULT, httpResult);
- service.addEventListener(FaultEvent.FAULT, httpFault);
- service.contentType = "application/json"
- service.headers = { Accept:"application/json" };
- service.send();
- }
- }
- // *************************************************
- // connectionSuccess
- // *************************************************
- private function httpResult(event:ResultEvent):void {
- var json:String = event.result as String;
- var obj:Object = JSON.decode(json);
- var tree:Object = obj.tree;
- treeView.dataProvider = object2json(tree);
- //MonsterDebugger.trace(this, treeView.dataProvider);
- MonsterDebugger.trace(this, treeView.selectedItem.label);
- }
- // *************************************************
- // generateJSONfromObject
- // *************************************************
- private function object2json(node:Object):Object{
- var name:String = node.name;
- var children:Array = new Array();
- if(isThereChildren(node)){
- for(var child:String in node.children){
- children.push(object2json(node.children[child]));
- }
- }
- if(isThereSubsymbols(node)){
- children.push(object2json(node.subsymbols[0]));
- }
- if(doYouHaveSomething(node)){
- return {label: name, children: children}
- }else{
- return {label: name}
- }
- }
- private function isThereChildren(nd:Object):Boolean{
- return nd.children
- }
- private function isThereSubsymbols(nd:Object):Boolean{
- return nd.subsymbols
- }
- private function doYouHaveSomething(nd:Object):Boolean{
- return nd.children || nd.subsymbols
- }
- // *************************************************
- // connectionFailure
- // *************************************************
- private function httpFault(event:FaultEvent):void {
- var faultstring:String = event.fault.faultString;
- Alert.show(faultstring);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement