summaryrefslogtreecommitdiff
path: root/alarm/node_modules/node-forge/tests/flash/Test.as
blob: 7c03727bdb052a03a06117f2774c11d6bb4cfea1 (plain)
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
93
94
95
96
/*
 * Copyright (c) 2010 Digital Bazaar, Inc. All rights reserved.
 * 
 * @author Dave Longley
 */
package
{
   import flash.display.Sprite;
   
   public class Test extends Sprite
   {
      import flash.events.*;
      import flash.net.*;
      
      import flash.external.ExternalInterface;
      import flash.system.Security;
      
      public function Test()
      {
         try
         {
            // FIXME: replace 'localhost' with cross-domain host to hit
            var xhost:String = "localhost";
            Security.loadPolicyFile("xmlsocket://" + xhost + ":80");
            
            var loader:URLLoader = new URLLoader();
            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);
            
            var request:URLRequest = new URLRequest(
               "http://" + xhost + "/index.html");
            loader.load(request);
         }
         catch(e:Error)
         {
            log("error=" + e.errorID + "," + e.name + "," + e.message);
            throw e;
         }
      }
      
      private function log(obj:Object):void
      {
         if(obj is String)
         {
            var str:String = obj as String;
            ExternalInterface.call("console.log", "Test", str);
         }
         else if(obj is Error)
         {
            var e:Error = obj as Error;
            log("error=" + e.errorID + "," + e.name + "," + e.message);
         }
      }
      
      private function completeHandler(event:Event):void
      {
         var loader:URLLoader = URLLoader(event.target);
         log("complete: " + loader.data);
      }

      private function openHandler(event:Event):void
      {
         log("open: " + event);
      }

      private function progressHandler(event:ProgressEvent):void
      {
         log("progress:" + event.bytesLoaded + " total: " + event.bytesTotal);
      }

      private function securityErrorHandler(event:SecurityErrorEvent):void
      {
         log("securityError: " + event);
      }

      private function httpStatusHandler(event:HTTPStatusEvent):void
      {
         log("httpStatus: " + event);
      }

      private function ioErrorHandler(event:IOErrorEvent):void
      {
         log("ioError: " + event);
      }
   }
}