NavigatetoURL and URL Request both Together doesn't work in Flex As3

Hi experts,

I have created sample code here.

I need to send two calls on different URL by clicking on one Button.

In my code I have created one URL Request to some PHP link..(You can use HTTP service too..It does same problem)..When Request to URL sent , I just place another code to navigatetoURL to another link.You can see the result only works with naviagetoURL ..Call to PHP link used by URLRequest FAIL..

How can I come out from this Problem?

When I try to use two HTTPservice that calls to different URL on SingleButton Click, It fails  with first call too..How can Flex work with Concurrent Calls /multiple calls with Single Button Click..?
I need to send two calls on different URL by clicking on one Button..How to achieve this?



 
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.rpc.http.HTTPService;
			
			private function Click() : void
			{
				
			var req :URLRequest = new URLRequest("http://www.snowflax.com/Bluetoad/test_clone.php");
			//FAIL CALL
     		var loader:URLLoader = new URLLoader();
     		
		     var params :URLVariables = new URLVariables();
		     params.p1 = "WHATEVER YOU WANT IT TO BE";
		     req.data = params;
		     req.method = URLRequestMethod.POST;
		     loader.load(req);
		    //PHP Call Hangs up here
		    
		     var urlRequest:URLRequest = new URLRequest("http://google.com");
			navigateToURL(urlRequest,"_blank"); 
			//Success CALL
			} 
		]]>
	</mx:Script>
	<mx:Button click="Click()">
		
	</mx:Button>
</mx:Application>

Open in new window

FAIL Call - First Call
LVL 1
mausamviki4allAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

blue-genieCommented:
i would recommned putting some listeners to check for errors to see where its failling

mausamviki4allAuthor Commented:
It doesn't FAIL but call never proceed in browser.
http://filedb.experts-exchange.com/incoming/2010/08_w33/337015/CAll-to-Service.png

Please check sample code here with browser on any sample PHP file.you will never get POST variable p1 in PHP/.NET at serverside..
mausamviki4allAuthor Commented:
I tried with HTTPSERVEVICE too,
 var _serv :HTTPService = new HTTPService();
            _serv.url="http://www.snowflax.com/Bluetoad/test_clone.php";
             _serv.request.data = "WHATEVER YOU WANT IT TO BE";
             _serv.method = "POST";
             _serv.send();

than
var urlRequest:URLRequest = new URLRequest("http://google.com");
            navigateToURL(urlRequest,"_blank");

POST to PHP files FAIL
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

blue-genieCommented:
if u don't do the navigateToURL afterwards, your POST is successful?
i don't have access to flex environment to setup test case.
blue-genieCommented:
ah wait i found an old version of flex on my desktop.
so if i click the button currently i get to google. are you saying in your case in hangs before then?
mausamviki4allAuthor Commented:
"if u don't do the navigateToURL afterwards, your POST is successful? "
Yes If I remove naviagetoURL,I can receive POSTED data from Flex to PHP


"so if i click the button currently i get to google. are you saying in your case in hangs before then?"
I can see only Google, but if you track the call
var req :URLRequest = new URLRequest("http://www.snowflax.com/Bluetoad/test_clone.php");
was in loop..as per FireBug sceenshot :CAll-to-Service.png
 


You can experience to same thin in below Example too..You never get google.com on Button Click..that's the problem here.Call me multiple URLs never process ,only last call happens.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
       <mx:Script>
       <![CDATA[
                   import mx.controls.Alert;
            import mx.controls.Button;

            public function addButton():void {
                var myButton:Button = new Button();
                myButton.label = "New Button";
                myHBox.addChild(myButton);
               
                myButton.addEventListener(MouseEvent.CLICK,clickHandler1)
               
            }
            function clickHandler1(event:MouseEvent):void
            {
                  //Alert.show("Hai");
                  navigateToURL(new URLRequest("http://www.google.com"));
                  navigateToURL(new URLRequest("http://www.yahoo.com"));
                  
                  
            }
        ]]>
    </mx:Script>

    <mx:HBox id="myHBox" initialize="addButton();"/>

</mx:Application>
blue-genieCommented:
very interesting.
i did some searching and found the issue.
it's the asynchronous nature of AS that is the problem.
here's the fix code sniippet attached.

src of snippet.

http://www.adobe.com/livedocs/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=passingarguments_086_12.html
<?xml version="1.0"?>
<!-- wrapper/NavigateToMultipleURLS.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="openWindows(0)">
  <mx:Script><![CDATA[
     import flash.net.navigateToURL;
     private var listingData:Array=[
        "http://www.google.com", 
        "http://www.adobe.com", 
        "http://www.usatoday.com"
     ];

     private function openWindows(n: Number):void {
        if (n < listingData.length) {
           navigateToURL(new URLRequest(listingData[n]), '_blank');
           callLater(callLater, [openWindows, [n+1]]);
        }
     }
  ]]></mx:Script>   
</mx:Application>

Open in new window

mausamviki4allAuthor Commented:
Thanks blue-genie..

thank you for your time and answer here..I really appreciate that but i still not get rid of real problem ..Currently it works with multiple navigatetoURL but how about HTTPService and navigatetoURL here

Can you please run this example in Flex and try it..How do I works with below code..I need one/multi httpservice call to PHP file and than redirect to google.com..currently I can't get POST data into PHP files due to asynchronous nature..!!
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.rpc.http.HTTPService;
			
			private function Click() : void
			{
				
			 var _serv :HTTPService = new HTTPService();
            _serv.url="http://www.snowflax.com/Bluetoad/test_clone.php";
             _serv.request.data = "WHATEVER YOU WANT IT TO BE";
             _serv.method = "POST";
             _serv.send(); 
		    //PHP Call Hangs up here
		    
		     var urlRequest:URLRequest = new URLRequest("http://google.com");
			navigateToURL(urlRequest,"_blank"); 
			//Success CALL
			} 
		]]>
	</mx:Script>
	<mx:Button click="Click()">
		
	</mx:Button>
</mx:Application>

Open in new window

blue-genieCommented:
you'll need to tweak this method

   private function openWindows(n: Number):void {
        if (n < listingData.length) {
           navigateToURL(new URLRequest(listingData[n]), '_blank');
           callLater(callLater, [openWindows, [n+1]]);
        }
     }

at work right now. will try at home for you later okay.
mausamviki4allAuthor Commented:
Finally It works with URLLoader and URLVariables.

Need to add listener wehn URL Loads,
loader.addEventListener(Event.COMPLETE,sendURL);

Send URL:
function  sendURL(event:Event):void
                  {
                  var urlRequest:URLRequest = new URLRequest("http://google.com");
                  navigateToURL(urlRequest,"_blank");
                  }


HTTPservice FAIL to load when we have parameters to send and than navigation..It does work without parameters.
If We use GET method in HTTPserive is works but FAIL when we have POST...amazing behavior.

Anyway,Check the corrected Code which works fine here..:)

Thanks blue-genie..
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.rpc.http.HTTPService;
			
			private function Click() : void
			{
				
			var req :URLRequest = new URLRequest("http://www.snowflax.com/Bluetoad/test_clone.php");
			
     		var loader:URLLoader = new URLLoader();
     		
		     var params :URLVariables = new URLVariables();
		     
		     params.e = "WHATEVER YOU WANT IT TO BE"; 
		     req.data = params;
		     req.method = URLRequestMethod.POST;
		     loader.load(req);
		    
		    loader.addEventListener(Event.COMPLETE,sendURL);
		    
			} 
			function  sendURL(event:Event):void
			{
			var urlRequest:URLRequest = new URLRequest("http://google.com");
			navigateToURL(urlRequest,"_blank");
			}
		]]>
	</mx:Script>
	<mx:Button click="Click()">
		
	</mx:Button>
</mx:Application>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CyanBlueCommented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.