Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.meerkat {
  2.    
  3.     import flash.events.NetStatusEvent;
  4.     import flash.net.NetConnection;
  5.     import flash.net.Responder;
  6.    
  7.     public class TestCase
  8.     {
  9.        
  10.         public var nc:NetConnection = new NetConnection();
  11.         public var serverUrl:String='';
  12.         public var callcounter:int = 0;
  13.  
  14.        
  15.         public function failure(...a):void{
  16.             trace('-----failure--------');
  17.         }
  18.        
  19.         public function success(...a):void{
  20.             trace('-----success--------');
  21.         }
  22.        
  23.         public function run():void
  24.         {
  25.             this.nc.connect(this.serverUrl);
  26.             this.nc.client = this;
  27.         }
  28.        
  29.         public function onNetStatus(event:NetStatusEvent):void
  30.         {
  31.             if (event.info.code != "NetConnection.Connect.Success")
  32.             {
  33.                 this.failure();
  34.                 return;
  35.             }
  36.             this.makeServerCall();
  37.         }
  38.        
  39.         /**
  40.          * Called from the server to test asynchronous result handling.
  41.          */
  42.         public function async_client_call():String
  43.         {
  44.             this.callcounter += 1;
  45.            
  46.             return 'bazgak';
  47.         }
  48.        
  49.         public function server_succeed():void
  50.         {
  51.             // called by the server if a successful roundtrip call is made.
  52.             this.callcounter += 1;
  53.            
  54.             this.checkSuccess();
  55.         }
  56.        
  57.        
  58.         public function checkSuccess():void
  59.         {
  60.             if (this.callcounter == 2)
  61.                 this.success();
  62.         }
  63.        
  64.        
  65.         public function makeServerCall():void
  66.         {
  67.             var onResult:Function = function(result:*):void
  68.             {
  69.                 if (result != 'foobar')
  70.                 {
  71.                     failure();
  72.                    
  73.                     return;
  74.                 }
  75.                
  76.                 checkSuccess();
  77.             };
  78.            
  79.             var onStatus:Function = function(info:*):void
  80.             {
  81.                 failure();
  82.             };
  83.            
  84.             var r:Responder = new Responder(onResult, onStatus);
  85.            
  86.             this.nc.call('async_server_call', r);
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement