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
Solved

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

Posted on 2010-08-14
12
1,765 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
anti-download video publishing site? 6 617
Accessing Live Dynamic Stream 6 200
embedding a media live encoder stream 3 148
HTML 5 video and audio or Flash 1 60
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

828 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