PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
dynamic url in httpservice (flex 3/AIR)
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: dynamic url in httpservice (flex 3/AIR)

  1. #1
    Member
    Join Date
    Feb 2008
    Posts
    31

    dynamic url in httpservice (flex 3/AIR)

    Hey everyone,
    I am trying to create an desktop app where the user selects an XML doc via a FileSystemTree. Then at the click of a button, that xml doc selected will be loaded in as the XML doc of choice. So far I have it working only if i hardcode in the path, but i need to make it so that the user can select the file dynamically.

    Thanks in advance for any help.


    Code:
    <?xml version="1.0" encoding="utf-8"?> 
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" 
           layout="vertical"
           width="520" height="400"
           verticalScrollPolicy="off"
           horizontalScrollPolicy="off"
           creationComplete = "initApp()" >
    
    <mx:Script> <![CDATA[            
    	import mx.controls.Alert;           
    	import mx.rpc.events.FaultEvent;
    	import mx.rpc.events.ResultEvent;
    
    	import mx.events.FileEvent;
    
    	import mx.utils.UIDUtil;  
    
    	[Bindable]            
    	public var _filePath:String;
    	
    	[Bindable]
    	private var xData:XML;
    
    	public function initApp():void { 
    		
    	}
          	private function onChooseFile(e:FileEvent):void { 
    		//trace("file name: " + e.file.nativePath); 
    		output.text = e.file.nativePath;  
    		_filePath = String(e.file.nativePath); 
    		trace("_filePath = " + _filePath); 
    		this.convertBtn.visible=true;
    	}
    	private function resultHandler(event:ResultEvent):void { 
    		xData = event.result as XML; 
    		trace("XML Load Success");    
    	} 
    	private function faultHandler(event:FaultEvent):void { 
    		Alert.show(event.fault.faultDetail, "Error"); 
    	}
    
    </mx:Script>
    
    <mx:HTTPService id="srv" url="{_filePath}"        
           result="resultHandler(event)"        
           resultFormat="e4x"        
           fault="faultHandler(event)" />
    
    <mx:FileSystemTree 
           width="400" 
           showIcons="true" 
           showExtensions="true"
            id="fileList" 
           fileChoose="onChooseFile(event)" 
           fontFamily="Verdana" fontSize="11"/> 
    
    <mx:TextInput id="output" width="400" fontFamily="Arial" fontStyle="normal" fontWeight="bold"/> 
    
    <mx:Button horizontalCenter="0" label="Convert XML for Proof" id="convertBtn" visible="false" click="srv.send()" />
     
    </mx:WindowedApplication>

  2. #2
    supervillain gerbick's Avatar
    Join Date
    Jul 2000
    Location
    undecided.
    Posts
    18,978
    I'm not seeing a true problem... although I did have to import FileSystemTree too:
    Actionscript Code:
    import mx.controls.Alert;          
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.controls.FileSystemTree;
    import mx.events.FileEvent;
    import mx.utils.UIDUtil;

    You shouldn't have to but on double click, I got your example to run, update on doubleclick - which, is somewhat annoying - but it works.

    Perhaps you're seeing an error? I'm not really seeing what the problem is - mind you, I might be overlooking something because it "works" here for me.

    Actionscript Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
           layout="vertical"
           width="520" height="400"
           verticalScrollPolicy="off"
           horizontalScrollPolicy="off"
           creationComplete = "initApp()"
           >

    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;          
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.controls.FileSystemTree;
            import mx.events.FileEvent;
            import mx.utils.UIDUtil;  

        [Bindable]            
        public var _filePath:String;
       
        [Bindable]
        private var xData:XML;

        public function initApp():void {
            //do something here
        }
        private function onChooseFile(event:FileEvent):void {
            //trace("file name: " + e.file.nativePath);
            output.text = event.file.nativePath;  
            _filePath = String(event.file.nativePath);
            trace("_filePath = " + _filePath);
            this.convertBtn.visible=true;
        }
        private function resultHandler(event:ResultEvent):void {
            xData = event.result as XML;
            trace("XML Load Success");    
        }
        private function faultHandler(event:FaultEvent):void {
            Alert.show(event.fault.faultDetail, "Error");
        }      
        ]]>
    </mx:Script>

    <mx:HTTPService id="srv" url="{_filePath}"        
           result="resultHandler(event)"        
           resultFormat="e4x"        
           fault="faultHandler(event)" />

    <mx:FileSystemTree
           width="400"
           showIcons="true"
           showExtensions="true"
           fileChoose="onChooseFile(event)"
           fontFamily="Verdana" fontSize="11"/>

    <mx:TextInput id="output" width="400" fontFamily="Arial" fontStyle="normal" fontWeight="bold"/>
    <mx:Button horizontalCenter="0" label="Convert XML for Proof" id="convertBtn" visible="false" click="srv.send()" />

    </mx:WindowedApplication>

    [ Hello ] | [ gerbick ] | [ Ω ]

  3. #3
    Member
    Join Date
    Feb 2008
    Posts
    31
    Thanks for the reply, Gerbick. I am actually getting an error:

    Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: app:/Folder/data/test.xml" errorID=2032]. URL: /Folder/data/test.xml

    it seems that it cant find the xml file to parse it when its selected from the filetree. It only seems to work if i hardcore the xml in and have it in the src folder of the application. Which completely destroys what i am trying to do. In the end i would like to be able to choose from a number of XML docs and be able to edit them through the flex interface i am designing. I have everything working pretty much other than that i cant get it to do the fileTree selection of the XML I need.

    and yes, the double click thing is annoying... any ideas there would be great.

    i appreciate the help

  4. #4
    supervillain gerbick's Avatar
    Join Date
    Jul 2000
    Location
    undecided.
    Posts
    18,978
    Hmm, I'm still trying to figure out what you're getting as an error, I'm still not seeing it.

    Code:
    [SWF] Test.swf - 1,569,367 bytes after decompression
    _filePath = C:\Downloads\data.xml
    XML Load Success
    That's from me making a quick XML file, dumping it into C:\Downloads\ and then going to get it. It works, knew the path, everything. Mind you, I'm testing on a PC, not my Mac per usual.

    If you give me some time, I might be able to test on my Mac - I'm currently rebuilding it due to a mishap on my own part.

    [ Hello ] | [ gerbick ] | [ Ω ]

  5. #5
    Member
    Join Date
    Feb 2008
    Posts
    31
    Again, Thanks for looking into it. Yeah, its really odd to me, I am trying to place any xml doc anywhere on my harddrive and still coming up with that error. I would appreticate if you too a look when you get your mac back up and running. I will get together some screenshots and post them on Monday, but thats pretty much it from what i told you. It SHOULD work, right? hmmm... i'm just not sure... As an output for this file, after adding trace("Alert Error :: " + event.fault.faultDetail); to the faultHandler, I get:

    Code:
    [SWF] main.swf - 1,535,882 bytes after decompression
    _filePath = /Users/wcrain/galleryList.xml
    Alert Error :: Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: app:/Users/wcrain/galleryList.xml" errorID=2032]. URL: /Users/wcrain/galleryList.xml
    Like i said, doesnt matter where i put the xml doc, same thing. I thought that maybe it was something else in the document, because it does do a lot more, so i stripped it down to just what i have in the initial post and still the same thing. Then I also tried releasing the app, installing and seeing if that had any change, but same thing. Even more frustrating since it seems to be working fine for you. This will be used in the end on both PCs and Macs, so i am happy to know that window like it

    I am putting in the script code again, only change is the addition of the trace in the faultHandler AND that I now set the srv.url in the onChooseFile function. My reason behind this was thinking perhaps the url isnt set quick enough and thats why it cant find the string path (although it is stating it in the error, so i dont think thats it really). It comes up with the exact same outcome though:

    Code:
    <?xml version="1.0" encoding="utf-8"?> 
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" 
           layout="vertical"
           width="520" height="400"
           verticalScrollPolicy="off"
           horizontalScrollPolicy="off"
           creationComplete = "initApp()" >
    
    <mx:Script> <![CDATA[            
    	import mx.controls.Alert;           
    	import mx.rpc.events.FaultEvent;
    	import mx.rpc.events.ResultEvent;
    	import mx.controls.FileSystemTree;
    	import mx.events.FileEvent;
    
    	import mx.utils.UIDUtil;  
    
    	[Bindable]            
    	public var _filePath:String;
    	
    	[Bindable]
    	private var xData:XML;
    
    	public function initApp():void { 
    		
    	}
          	private function onChooseFile(event:FileEvent):void { 
    		//trace("file name: " + event.file.nativePath); 
    		output.text = event.file.nativePath;  
    		_filePath = String(event.file.nativePath);
    		srv.url= _filePath;  
    		trace("_filePath = " + _filePath); 
    		this.convertBtn.visible=true;
    	}
    	private function resultHandler(event:ResultEvent):void { 
    		xData = event.result as XML; 
    		trace("XML Load Success");    
    	} 
    	private function faultHandler(event:FaultEvent):void { 
    		trace("Alert Error :: " + event.fault.faultDetail);
    		Alert.show(event.fault.faultDetail, "Error"); 
    	}
     ]]>
    </mx:Script>
    
    <mx:HTTPService id="srv"        
           result="resultHandler(event)"        
           resultFormat="e4x"        
           fault="faultHandler(event)" />
    
    <mx:FileSystemTree 
           width="400" 
           showIcons="true" 
           showExtensions="true"
            id="fileList" 
           fileChoose="onChooseFile(event)" 
           fontFamily="Verdana" fontSize="11"/> 
    
    <mx:TextInput id="output" width="400" fontFamily="Arial" fontStyle="normal" fontWeight="bold"/> 
    
    <mx:Button horizontalCenter="0" label="Convert XML for Proof" id="convertBtn" visible="false" click="srv.send()" />
     
    </mx:WindowedApplication>

    I dont want to give up on doing this this way yet, unless there is a better way. a more "right way" that someone could suggest. the other thought that i had was to set it up so that the path is defined in the onChooseFile function then using AS3 set up a xmlLoader and bring it in that way. Any disadvantages to doing this, anyone? I do want to be able to add to and edit the xml docs, which is what the rest of my app does at this time (not in the above script)


    Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center