Link to home
Start Free TrialLog in
Avatar of mausamviki4all
mausamviki4all

asked on

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

User generated image
Avatar of blue-genie
blue-genie
Flag of South Africa image

i would recommned putting some listeners to check for errors to see where its failling

Avatar of mausamviki4all
mausamviki4all

ASKER

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..
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
if u don't do the navigateToURL afterwards, your POST is successful?
i don't have access to flex environment to setup test case.
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?
"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>
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

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

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.
ASKER CERTIFIED SOLUTION
Avatar of mausamviki4all
mausamviki4all

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.