-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMakeRequest.mxml
executable file
·92 lines (67 loc) · 2.91 KB
/
MakeRequest.mxml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;
import mx.controls.Alert;
import flash.external.ExternalInterface;
var loader:URLLoader = new URLLoader();
[Bindable] public var html:String = "";
public function URLLoaderExample():void {
loader = new URLLoader();
configureListeners(loader);
var url:String = url_input1.text;
var post:String = url_input2.text;
var request:URLRequest = new URLRequest(url);
if (post) {
ExternalInterface.call("alert", "Making POST request to: " + url);
request.method = URLRequestMethod.POST;
request.data = post;
}
else {
ExternalInterface.call("alert", "Making GET request to: " + url);
}
try {
loader.load(request);
} catch (error:Error) {
trace("Unable to load requested document.");
}
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
private function completeHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
html = loader.data;
}
private function openHandler(event:Event):void {
trace("openHandler: " + event);
}
private function progressHandler(event:ProgressEvent):void {
trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function httpStatusHandler(event:HTTPStatusEvent):void {
trace("httpStatusHandler: " + event);
}
private function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
]]>
</fx:Script>
<s:TextInput id="url_input1" text="[URL] ex: http://www.example.com/?id=1" width="500" x="10" y="0"/>
<s:TextInput id="url_input2" text="[POST] ex: test=1 (delete text for GET requests)" width="500" x="10" y="30"/>
<s:TextArea text="Result {html}" width="500" height="400" x="10" y="60"/>
<s:Button label="Send" click="URLLoaderExample()" x="10" y="470"/>
</s:Application>