Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-08-14
12
Medium Priority
?
1,911 Views
Last Modified: 2013-11-11
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
0
Comment
Question by:mausamviki4all
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
12 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 33436810
i would recommned putting some listeners to check for errors to see where its failling

0
 
LVL 1

Author Comment

by:mausamviki4all
ID: 33440123
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..
0
 
LVL 1

Author Comment

by:mausamviki4all
ID: 33440124
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Expert Comment

by:blue-genie
ID: 33444251
if u don't do the navigateToURL afterwards, your POST is successful?
i don't have access to flex environment to setup test case.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 33444270
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?
0
 
LVL 1

Author Comment

by:mausamviki4all
ID: 33444494
"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>
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 33444614
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

0
 
LVL 1

Author Comment

by:mausamviki4all
ID: 33444716
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

0
 
LVL 39

Expert Comment

by:blue-genie
ID: 33444753
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.
0
 
LVL 1

Accepted Solution

by:
mausamviki4all earned 0 total points
ID: 33445147
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

0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 34049969
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.
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question