flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject git commit: [flex-asjs] [refs/heads/develop] - Added more URL loading event support
Date Thu, 07 Jul 2016 19:42:13 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop 8770b6704 -> 9e43d9a58


Added more URL loading event support


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/9e43d9a5
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/9e43d9a5
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/9e43d9a5

Branch: refs/heads/develop
Commit: 9e43d9a5862a8efeef329795a0e732761a44f5ea
Parents: 8770b67
Author: Harbs <harbs@in-tools.com>
Authored: Thu Jul 7 22:42:07 2016 +0300
Committer: Harbs <harbs@in-tools.com>
Committed: Thu Jul 7 22:42:07 2016 +0300

----------------------------------------------------------------------
 .../projects/Core/src/main/flex/CoreClasses.as  |   2 +-
 .../flex/org/apache/flex/events/DetailEvent.as  |  60 +++++++
 .../flex/org/apache/flex/events/StringEvent.as  |  60 -------
 .../flex/org/apache/flex/net/HTTPConstants.as   |  14 +-
 .../flex/org/apache/flex/net/URLBinaryLoader.as |   2 +-
 .../main/flex/org/apache/flex/net/URLRequest.as |  49 +++++-
 .../main/flex/org/apache/flex/net/URLStream.as  | 165 ++++++++++++++++---
 7 files changed, 266 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9e43d9a5/frameworks/projects/Core/src/main/flex/CoreClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/CoreClasses.as b/frameworks/projects/Core/src/main/flex/CoreClasses.as
index ab41144..5796927 100644
--- a/frameworks/projects/Core/src/main/flex/CoreClasses.as
+++ b/frameworks/projects/Core/src/main/flex/CoreClasses.as
@@ -103,7 +103,7 @@ internal class CoreClasses
     import org.apache.flex.events.EventDispatcher; EventDispatcher;
     import org.apache.flex.events.IEventDispatcher; IEventDispatcher;
 	import org.apache.flex.events.MouseEvent; MouseEvent;
-	import org.apache.flex.events.StringEvent; StringEvent;
+	import org.apache.flex.events.DetailEvent; DetailEvent;
 	import org.apache.flex.events.ValueEvent; ValueEvent;
     import org.apache.flex.events.utils.MouseUtils; MouseUtils;
     import org.apache.flex.geom.Point; Point;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9e43d9a5/frameworks/projects/Core/src/main/flex/org/apache/flex/events/DetailEvent.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/DetailEvent.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/DetailEvent.as
new file mode 100644
index 0000000..0e8817a
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/DetailEvent.as
@@ -0,0 +1,60 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.events
+{
+    
+    /**
+     *  The DetailEvent class is used for dispatching an event
+	 *  that has a string with more information
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+	public class DetailEvent extends Event
+	{
+        /**
+         *  Constructor.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+		public function DetailEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false,

+									detail:String = null)
+		{
+			super(type, bubbles, cancelable);
+            
+			this.detail = detail;
+		}
+		
+        /**
+         *  The detail.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+		public var detail:String;
+
+	}
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9e43d9a5/frameworks/projects/Core/src/main/flex/org/apache/flex/events/StringEvent.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/StringEvent.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/StringEvent.as
deleted file mode 100644
index fa24932..0000000
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/StringEvent.as
+++ /dev/null
@@ -1,60 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////
-//
-//  Licensed to the Apache Software Foundation (ASF) under one or more
-//  contributor license agreements.  See the NOTICE file distributed with
-//  this work for additional information regarding copyright ownership.
-//  The ASF licenses this file to You under the Apache License, Version 2.0
-//  (the "License"); you may not use this file except in compliance with
-//  the License.  You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-//  Unless required by applicable law or agreed to in writing, software
-//  distributed under the License is distributed on an "AS IS" BASIS,
-//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//  See the License for the specific language governing permissions and
-//  limitations under the License.
-//
-////////////////////////////////////////////////////////////////////////////////
-package org.apache.flex.events
-{
-    
-    /**
-     *  The StringEvent class is used for dispatching an event
-	 *  that has a string payload
-     *  
-     *  @langversion 3.0
-     *  @playerversion Flash 10.2
-     *  @playerversion AIR 2.6
-     *  @productversion FlexJS 0.0
-     */
-	public class StringEvent extends Event
-	{
-        /**
-         *  Constructor.
-         *  
-         *  @langversion 3.0
-         *  @playerversion Flash 10.2
-         *  @playerversion AIR 2.6
-         *  @productversion FlexJS 0.0
-         */
-		public function StringEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false,

-									payload:String = null)
-		{
-			super(type, bubbles, cancelable);
-            
-			this.payload = payload;
-		}
-		
-        /**
-         *  The value.
-         *  
-         *  @langversion 3.0
-         *  @playerversion Flash 10.2
-         *  @playerversion AIR 2.6
-         *  @productversion FlexJS 0.0
-         */
-		public var payload:String;
-
-	}
-}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9e43d9a5/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPConstants.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPConstants.as
b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPConstants.as
index 552a745..7060966 100644
--- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPConstants.as
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/HTTPConstants.as
@@ -84,10 +84,20 @@ package org.apache.flex.net
          *  @playerversion AIR 2.6
          *  @productversion FlexJS 0.0
          */
-        public static const IO_ERROR:String = "ioError";
+        public static const COMMUNICATION_ERROR:String = "communicationError";
 
 		/**
-		 *  Dispatched if a security error occurs in the server communication.
+		 *  Detail of an error occurring in the server communication. (Flash only)
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public static const IO_ERROR:String = "ioError";
+
+		/**
+		 *  Detail of a security error occurs in the server communication. (Flash only)
 		 *  
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9e43d9a5/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLBinaryLoader.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLBinaryLoader.as
b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLBinaryLoader.as
index f313b3a..e677245 100644
--- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLBinaryLoader.as
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLBinaryLoader.as
@@ -90,7 +90,7 @@ package org.apache.flex.net
 		 */        
         public var bytesTotal:uint = 0;
         
-        public function URLBinaryLoader(request:URLRequest = null)
+        public function URLBinaryLoader()
         {
             super();
             stream = new URLStream();

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9e43d9a5/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequest.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequest.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequest.as
index 930ae8e..c9db327 100644
--- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequest.as
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLRequest.as
@@ -18,11 +18,58 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.net
 {
+	/**
+	 *  The URLRequest class captures all of the information in a single HTTP request.
+	 *  URLRequest objects are passed to the load() methods of the URLStream,
+	 *  and URLLoader classes, and to other loading operations, to initiate URL downloads.
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion FlexJS 0.7.0
+	 */
     public final class URLRequest extends Object
     {
-        public var url:String;
+		/**
+		 *  The URL to be requested.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.7.0
+		 */	
+        
+		public var url:String;
+		
+		/**
+		 *  An object containing data to be transmitted with the URL request. 
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.7.0
+		 */	
         public var data:Object;
+		
+		/**
+		 *   Controls the HTTP form submission method.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.7.0
+		 */	
         public var contentType:String = "application/x-www-form-urlencoded";
+		
+		/**
+		 *   Controls the HTTP form submission method.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.7.0
+		 */	
+		public var method:String = HTTPConstants.GET;
         
         public function URLRequest(url:String = null)
         {

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9e43d9a5/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as
index b3754de..0d27b68 100644
--- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as
@@ -21,6 +21,11 @@ package org.apache.flex.net
     
     
     
+    import flash.events.HTTPStatusEvent;
+    import flash.events.SecurityErrorEvent;
+    import flash.events.StatusEvent;
+    
+    import org.apache.flex.events.DetailEvent;
     import org.apache.flex.events.Event;
     import org.apache.flex.events.EventDispatcher;
     import org.apache.flex.events.ProgressEvent;
@@ -58,6 +63,26 @@ package org.apache.flex.net
             super();
         }
         
+		/**
+		 *  The number of bytes loaded so far.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.7.0
+		 */        
+		public var bytesLoaded:uint = 0;
+		
+		/**
+		 *  The total number of bytes (if avaailable).
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.7.0
+		 */        
+		public var bytesTotal:uint = 0;
+
         public function get response():BinaryData
         {
             COMPILE::JS
@@ -76,7 +101,7 @@ package org.apache.flex.net
         {
             COMPILE::JS {
                 xhr = new XMLHttpRequest();
-                xhr.open("POST", urlRequest.url);
+                xhr.open(urlRequest.method, urlRequest.url);
                 xhr.responseType = "arraybuffer";
                 xhr.addEventListener("readystatechange", xhr_onreadystatechange,false);
                 xhr.addEventListener("progress", xhr_progress, false);
@@ -91,55 +116,119 @@ package org.apache.flex.net
                 req.requestHeaders.push(hdr);
                 req.data = new flash.net.URLVariables(HTTPUtils.encodeUrlVariables(urlRequest.data));
                 req.method = HTTPConstants.POST;
+				flashUrlStream.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, flash_status);
+				flashUrlStream.addEventListener(HTTPStatusEvent.HTTP_STATUS, flash_status);
                 flashUrlStream.addEventListener(flash.events.ProgressEvent.PROGRESS, flash_progress);
                 flashUrlStream.addEventListener(flash.events.Event.COMPLETE, flash_complete);
                 flashUrlStream.addEventListener(IOErrorEvent.IO_ERROR, flash_onIoError);
+				flashUrlStream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, flash_onSecurityError);
                 flashUrlStream.load(req);
             }
         }
-        
+        COMPILE::SWF
+		private function flash_status(ev:StatusEvent):void
+		{
+			setStatus(parseInt(ev.code,10));
+		}
+		
         COMPILE::SWF 
         protected function flash_onIoError(event:IOErrorEvent):void
         {
-            trace("io error: " + event.text);
-        }            
+			dispatchEvent(new DetailEvent(HTTPConstants.COMMUNICATION_ERROR,false,false,HTTPConstants.IO_ERROR));
+			//Is there useful text?
+            //trace("io error: " + event.text);
+			if(onError)
+				onError(this);
+			cleanupCallbacks();
+        }
+		
+		COMPILE::SWF
+		private function flash_onSecurityError(ev:flash.events.Event):void
+		{
+			dispatchEvent(new DetailEvent(HTTPConstants.COMMUNICATION_ERROR,false,false,HTTPConstants.SECURITY_ERROR));
+			if(onError)
+				onError(this);
+			cleanupCallbacks();
+		}
             
         COMPILE::SWF
         protected function flash_complete(event:flash.events.Event):void
         {
             dispatchEvent(new org.apache.flex.events.Event(HTTPConstants.COMPLETE));
 			if(onComplete)
-				onComplete();
+				onComplete(this);
 			cleanupCallbacks();
         }
         COMPILE::SWF
-        protected function flash_progress(event:flash.events.ProgressEvent):void
+        protected function flash_progress(ev:flash.events.ProgressEvent):void
         {
-            var progressEvent:org.apache.flex.events.ProgressEvent = new org.apache.flex.events.ProgressEvent(org.apache.flex.events.ProgressEvent.PROGRESS);
-            progressEvent.current = event.bytesLoaded;
-            progressEvent.total = event.bytesTotal;
-            dispatchEvent(progressEvent);
+            var progEv:org.apache.flex.events.ProgressEvent = new org.apache.flex.events.ProgressEvent(org.apache.flex.events.ProgressEvent.PROGRESS);
+			
+			progEv.current = bytesLoaded = ev.bytesLoaded;
+			progEv.total = bytesTotal = ev.bytesTotal;
+            dispatchEvent(progEv);
+			if(onProgress)
+				onProgress(this);
         }
         
-        
+        COMPILE::JS
         private function xhr_progress(e:Object):void 
         {
-            dispatchEvent(new org.apache.flex.events.ProgressEvent(org.apache.flex.events.ProgressEvent.PROGRESS,
false, false, e.loaded, e.total));
+			var progEv:ProgressEvent = new ProgressEvent(ProgressEvent.PROGRESS);
+			progEv.current = bytesLoaded = e.loaded;
+			progEv.total = bytesTotal = e.total;
+			
+            dispatchEvent(progEv);
+			if(onProgress)
+				onProgress(this);
         }
         
         COMPILE::JS
         private function xhr_onreadystatechange(e:*):void
         {
-            if (xhr.readyState == 4 && xhr.status == 200)
-            {
-                dispatchEvent(new org.apache.flex.events.Event(HTTPConstants.COMPLETE));
+			setStatus(xhr.status);
+			//we only need to deal with the status when it's done.
+			if(xhr.readyState != 4)
+				return;
+			if(xhr.status == 0)
+			{
+				//Error. We don't know if there's a network error or a CORS error so there's no detail
+				dispatchEvent(new DetailEvent(HTTPConstants.COMMUNICATION_ERROR));
+				if(onError)
+					onError(this);
+			}
+			else if(xhr.status < 200)
+			{
+				dispatchEvent(new DetailEvent(HTTPConstants.COMMUNICATION_ERROR,false,false,""+requestStatus));
+				if(onError)
+					onError(this);
+			}
+			else if(xhr.status < 300)
+			{
+				dispatchEvent(new org.apache.flex.events.Event(HTTPConstants.COMPLETE));
 				if(onComplete)
 					onComplete();
-				cleanupCallbacks();
-            }else if (xhr.readyState==4&&xhr.status==404){
-                //                    dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR));
-            }
+				
+			}
+			else
+			{
+				dispatchEvent(new DetailEvent(HTTPConstants.COMMUNICATION_ERROR,false,false,""+requestStatus));
+				if(onError)
+					onError(this);
+			}
+			cleanupCallbacks();
         }
+		
+		private function setStatus(value:int):void
+		{
+			if(value != requestStatus)
+			{
+				requestStatus = value;
+				dispatchEvent(new DetailEvent(HTTPConstants.STATUS,false,false,""+value));
+				if(onStatus)
+					onStatus(this);
+			}
+		}
 
         public function close():void
         {
@@ -157,7 +246,17 @@ package org.apache.flex.net
 			cleanupCallbacks();
 
         }
-		
+
+		/**
+		 *  Indicates the status of the request.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.7.0
+		 */        
+		public var requestStatus:int = 0;
+
 		/**
 		 *  Indicates the byte order for the data.
 		 *  
@@ -173,6 +272,7 @@ package org.apache.flex.net
 			onComplete = null;
 			onError = null;
 			onProgress = null;
+			onStatus = null;
 		}
 		/**
 		 *  Callback for complete event.
@@ -203,7 +303,17 @@ package org.apache.flex.net
 		 *  @productversion FlexJS 0.7.0
 		 */		
 		public var onProgress:Function;
-		
+
+		/**
+		 *  Callback for status event.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.7.0
+		 */		
+		public var onStatus:Function;
+
 		/**
 		 *  Convenience function for complete event to allow chaining.
 		 *  
@@ -245,6 +355,19 @@ package org.apache.flex.net
 			onProgress = callback;
 			return this;
 		}
+		/**
+		 *  Convenience function for status event to allow chaining.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.7.0
+		 */		
+		public function status(callback:Function):org.apache.flex.net.URLStream
+		{
+			onStatus = callback;
+			return this;
+		}
 }
 }
 


Mime
View raw message