?
Solved

URLLoader in action script 3.0

Posted on 2011-10-17
14
Medium Priority
?
783 Views
Last Modified: 2013-11-11
Hi Experts,

I am new to flash action script3.0

I am seeing method submitCompleteHandler

and it is loading url

var loader:URLLoader = URLLoader(event.target);

My first question is how event.target knows about target. Is it passing same as this._backendURL

Is method name onIOErrorHandler called when it is failed to call the URL

or this method is called when url loaded has the error

or on both cases


Another how we receive message from url loaded, if result is success or failure

Please guide

Thanks
protected function submitPOST(variables:URLVariables):void {
	var request:URLRequest = new URLRequest(this._backendURL);
	request.method = URLRequestMethod.POST;
	request.data = variables;

	var loader = new URLLoader();
	loader.dataFormat = URLLoaderDataFormat.VARIABLES;

	trace("DataConnector: url="+this._backendURL+" data="+request.data);

	loader.addEventListener(Event.COMPLETE, submitCompleteHandler);
	loader.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorHandler);

	loader.load(request);
}


// submittion complete handler
protected function submitCompleteHandler(event:Event):void {
	var loader:URLLoader = URLLoader(event.target);
	trace("DataConnector: url="+this._backendURL+"   Feedback=" + loader.data);
}



// submittion error handler
protected function onIOErrorHandler(event:IOErrorEvent):void {
	ExternalInterface.call("alert", "DataConnector: Error submitting your details to the database. \n\n"+event.toString());
	trace("DataConnector: url="+this._backendURL+"   ERROR=" + event.toString());
	//popAlert("Error submitting your details to the database", yourfirstname);
}

Open in new window

0
Comment
Question by:tia_kamakshi
  • 8
  • 6
14 Comments
 
LVL 29

Accepted Solution

by:
dgofman earned 2000 total points
ID: 36981092
Please check a documentation and example

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html#includeExamplesSummary 

When you are testing a first time your request I will suggest temporary add all those event listeners

loader.addEventListener(Event.COMPLETE, completeHandler);
loader.addEventListener(Event.OPEN, openHandler);
loader.addEventListener(ProgressEvent.PROGRESS, progressHandler);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
0
 

Author Comment

by:tia_kamakshi
ID: 36986706
Thanks for this.

I will check this tmmorow morning and update you with results

Thanks again

Best Regards
0
 

Author Comment

by:tia_kamakshi
ID: 36990753
Hi,

I have added all the events as you suggested. Still I am getting error

Subscriber Connector: Error submitting your details to the database.

[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://dxbmiwwekdev1:1313/aspx/subscribe.aspx"]

and log says:


SubscribeConnector: new connection
Calling submitPOST()
DataConnector: url=http://dxbmiwwekdev1:1313/aspx/subscribe.aspx data=utitle=Mr&joincomp=1&bonus=0&country=AU&sequence=&sendnews=1&lastname=gh&email=jhgjg%40jdk%2Ecom&journeyname=dfgd&firstname=gfhgf&showgallery=1
Dinesh 55
Dinesh 55.1
Dinesh 55.2
Dinesh 55.3
Dinesh 55.4
Dinesh 55.5
Dinesh 55.6
Dinesh 55.7
Calling submitPOST() completed
Calling WebServiceConnector2()
Calling WebServiceConnector2()... completed
Jumping to Page: 13... Dinesh in save form... commented for a while
Jumping to Page: 13... Dinesh ... Done
Data Submitting... done
openHandler: [Event type="open" bubbles=false cancelable=false eventPhase=2]
httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=500 responseURL=null]
Dinesh 45.001
Dinesh 45.1: Subscriber Connector: Error submitting your details to the database.

[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://dxbmiwwekdev1:1313/aspx/subscribe.aspx"]


Please guide

loader.addEventListener(Event.COMPLETE, submitCompleteHandler);
		trace("Dinesh 55.1");
		loader.addEventListener(Event.OPEN, openHandler);
		trace("Dinesh 55.2");
		loader.addEventListener(ProgressEvent.PROGRESS, progressHandler);
		trace("Dinesh 55.3");
		loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
		trace("Dinesh 55.4");
		loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
		trace("Dinesh 55.5");
		loader.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorHandler);
		trace("Dinesh 55.6");
		
		try {
                loader.load(request);
            } catch (error:Error) {
                trace("Unable to load requested document.");
            }

			
			trace("Dinesh 55.7");
		}
		
		// submittion complete handler
		protected function submitCompleteHandler(event:Event):void {
			trace("Dinesh 64.11");
			trace("DataConnector64: url="+this._backendURL+"   Feedback=" + loader.data);
			var loader:URLLoader = URLLoader(event.target);
			trace("DataConnector: url="+this._backendURL+"   Feedback=" + loader.data);
		}

		// submittion error handler
		protected function onIOErrorHandler(event:IOErrorEvent):void {
			trace("DataConnector: Error submitting your details to the database. \n\n"+event.toString());
			trace("DataConnector: url="+this._backendURL+"   ERROR=" + event.toString());
			ExternalInterface.call("alert", "DataConnector: Error submitting your details to the database. \n\n"+event.toString());
			trace("DataConnector: url="+this._backendURL+"   ERROR=" + event.toString());
			//popAlert("Error submitting your details to the database", yourfirstname);
		}
		
		protected function openHandler(event:Event):void {
            trace("openHandler: " + event);
        }

        protected function progressHandler(event:ProgressEvent):void {
            trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
        }

        protected function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }

        protected function httpStatusHandler(event:HTTPStatusEvent):void {
            trace("httpStatusHandler: " + event);
        }

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:tia_kamakshi
ID: 36990792
After the above post, Even I have removed my subscribers.aspx file and just calling simple test.html with code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>test</title>

</head>
<body>
test
</body>
</html>


and it giving still the same error:
[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://dxbmiwwekdev1:1313/aspx/test.html"]


log says:

Saving Data
Test
--------------->string
Dinesh 5
UserData - setFirstName(fg)
Data Saved
Data Submitting...
SubscribeConnector: new connection
Calling submitPOST()
DataConnector: url=http://dxbmiwwekdev1:1313/aspx/test.html data=lastname=dfg&bonus=0&email=dgf%40wer%2Ecom&utitle=Mr&showgallery=1&sequence=&joincomp=1&country=AU&journeyname=sdfgf&firstname=fg&sendnews=1
Dinesh 55
Dinesh 55.1
Dinesh 55.2
Dinesh 55.3
Dinesh 55.4
Dinesh 55.5
Dinesh 55.6
Dinesh 55.7
Calling submitPOST() completed
Calling WebServiceConnector2()
Calling WebServiceConnector2()... completed
Jumping to Page: 13... Dinesh in save form... commented for a while
Jumping to Page: 13... Dinesh ... Done
Data Submitting... done
openHandler: [Event type="open" bubbles=false cancelable=false eventPhase=2]
httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=405 responseURL=null]
Dinesh 45.001
Dinesh 45.1: Subscriber Connector: Error submitting your details to the database.

[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://dxbmiwwekdev1:1313/aspx/test.html"]


Please guide
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36990801
Can you point to localhost and run server instead

http://dxbmiwwekdev1:1313/aspx

use
http://localhost:1313/aspx

by the way why you have aspx + test.html
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36990804
You have to pointing to your server responce data not to HTML page

HTML responce is invalid for parsering containts HTML tags
0
 

Author Comment

by:tia_kamakshi
ID: 36990831
I am testing on development server only by copying the files there. My localhost environment is not setup.

Therefore I cannot do test on localhost

Just for test I have removed subscribers.aspx and used html file instead, thought might be it swf is getting some kind of error when running aspx file

so i used html file instead.

Also the thing is when I use aspx file, my data also got inserted in the database. I only have to insert data from database

Please guide

0
 
LVL 29

Expert Comment

by:dgofman
ID: 36990842
Just think first, HTML is static context how HTML can pass value to the database and create return confermation streaming bytes????

Another problem why I asked to test locally because you may getting crossdomain security exception, but actually should be catched by securityErrorHandler handler
0
 

Author Comment

by:tia_kamakshi
ID: 36990879
y crossdomain.xml has the access to local server

<allow-access-from domain="*" />

so, I am not getting security error

so, I will put back my aspx file

what kind of response swf file looks from asx file. May be it is not getting valid response from aspx file, so we are getting error

Also, httpStatusHandler is giving status=405 as below

httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=405 responseURL=null]

But before modifying my code, I was not getting any such error

Please suggest
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36990887
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36990897
0
 

Author Comment

by:tia_kamakshi
ID: 36990919
Hi understand my test.html file is invalid.

It is doing nothing, so I don't need this setting in IIS

Now I am back calling subscribers.aspx file, which can accept POST/GET methods

If you see my post above for aspx file as well it is giving same error

Please help me in solving this issue

Many Thanks again for your co-operation
0
 

Author Comment

by:tia_kamakshi
ID: 36990964
Sorry, In case of aspx file it is giving 500 error

httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=500 responseURL=null]

that means it is aspx file issue


SubscribeConnector: new connection
Calling submitPOST()
DataConnector: url=http://dxbmiwwekdev1:1313/aspx/subscribe.aspx data=utitle=Mr&joincomp=1&bonus=0&country=AU&sequence=&sendnews=1&lastname=gh&email=jhgjg%40jdk%2Ecom&journeyname=dfgd&firstname=gfhgf&showgallery=1
Dinesh 55
Dinesh 55.1
Dinesh 55.2
Dinesh 55.3
Dinesh 55.4
Dinesh 55.5
Dinesh 55.6
Dinesh 55.7
Calling submitPOST() completed
Calling WebServiceConnector2()
Calling WebServiceConnector2()... completed
Jumping to Page: 13... Dinesh in save form... commented for a while
Jumping to Page: 13... Dinesh ... Done
Data Submitting... done
openHandler: [Event type="open" bubbles=false cancelable=false eventPhase=2]
httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=500 responseURL=null]


Please suggest
0
 

Author Closing Comment

by:tia_kamakshi
ID: 36993194
It was the issue with aspx file only. HttpsatusHandler helped me identifying the issue

Many Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
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
Course of the Month16 days, 22 hours left to enroll

862 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