You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2018/09/23 07:31:10 UTC

[royale-asjs] branch develop updated: working example in all browsers but IE11 still has some issue

This is an automated email from the ASF dual-hosted git repository.

carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 2ce4d57  working example in all browsers but IE11 still has some issue
2ce4d57 is described below

commit 2ce4d57e2379cab613570fa5bf37ba8f65f9d5ad
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Sun Sep 23 09:31:03 2018 +0200

    working example in all browsers but IE11 still has some issue
---
 ...ithub_external_data_through_HTTPService.as3proj |  4 +-
 .../README.txt                                     |  5 ++-
 ...g_Github_external_data_through_HTTPService.mxml | 29 ++++++++++---
 .../src/main/royale/services/GitHubService.as      | 49 ++++++++++++++++------
 4 files changed, 65 insertions(+), 22 deletions(-)

diff --git a/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/BE0011_Loading_Github_external_data_through_HTTPService.as3proj b/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/BE0011_Loading_Github_external_data_through_HTTPService.as3proj
index f904c84..c1f771c 100644
--- a/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/BE0011_Loading_Github_external_data_through_HTTPService.as3proj
+++ b/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/BE0011_Loading_Github_external_data_through_HTTPService.as3proj
@@ -20,7 +20,7 @@
 <project>
   <output>
     <movie disabled="False"/>
-    <movie path="bin-debug/BE0010_Customization_through_the_Royale_API.swf"/>
+    <movie path="bin-debug/BE0011_Loading_Github_external_data_through_HTTPService.swf"/>
     <movie version="11"/>
     <movie input=""/>
     <movie width="800"/>
@@ -69,7 +69,7 @@
   </intrinsics>
   <library></library>
   <compileTargets>
-    <compile path="src/main/royale/BE0010_Customization_through_the_Royale_API.mxml"/>
+    <compile path="src/main/royale/BE0011_Loading_Github_external_data_through_HTTPService.mxml"/>
   </compileTargets>
   <hiddenPaths></hiddenPaths>
   <preBuildCommand>null</preBuildCommand>
diff --git a/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/README.txt b/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/README.txt
index 0ae715c..c3450c0 100644
--- a/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/README.txt
+++ b/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/README.txt
@@ -19,9 +19,10 @@
 
 DESCRIPTION
 
-Customization through the Royale API
+Loading Github external data through HTTPService
 
-Learn how to use the powerful Royale APIs to get access to internals and customize to your needs in a Royale application.
+Learn how to use the HTTPService to load external data from a server. In this case we load the source code of
+this example using the Github API in a Royale panel to browse it.
 
 Source code of the code exposed in the following Apache Royale Blog Example post:
 
diff --git a/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/src/main/royale/BE0011_Loading_Github_external_data_through_HTTPService.mxml b/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/src/main/royale/BE0011_Loading_Github_external_data_through_HTTPService.mxml
index b4db405..fa06172 100644
--- a/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/src/main/royale/BE0011_Loading_Github_external_data_through_HTTPService.mxml
+++ b/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/src/main/royale/BE0011_Loading_Github_external_data_through_HTTPService.mxml
@@ -25,16 +25,29 @@
 
     <fx:Script>
 		<![CDATA[
-            public var github_url:String = "https://api.github.com/repos/apache/royale-asjs/contents/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml";
+            import org.apache.royale.events.Event;
+            import org.apache.royale.events.MouseEvent;
+            import org.apache.royale.jewel.Alert;
 
+            public function getGithubContent(event:MouseEvent):void
+            {
+                service.getContent();
+            }
+            
             public function dataReadyHandler(event:Event):void
 			{
-                sourceCodeTextHolder.text = event.target.data;
+                Alert.show(event.target.jsonToString, "JSON data retrieved");
+                jsonData.html = "Some JSON Data: <br><strong> - service.json.name:</strong> " + service.json.name + 
+                                "<br><strong> - service.json.sha:</strong> " + service.json.sha +
+                                "<br><strong> - service.json._links.html</strong> " + service.json._links.html;
+                sourceCodeMXMLText.text =  service.sourceCode;
 			}
 		]]>
 	</fx:Script>
-
-    <services:GitHubService id="service" dataReady="dataReadyHandler(event)"/>
+    
+    <services:GitHubService id="service" 
+                            sourceCodeUrl="https://api.github.com/repos/apache/royale-asjs/contents/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/src/main/royale/BE0011_Loading_Github_external_data_through_HTTPService.mxml"
+                            dataReady="dataReadyHandler(event)"/>
 
     <j:initialView>
         <j:View>
@@ -45,14 +58,18 @@
             <j:Card percentWidth="90">
                 <html:H3 text="Loading Github external data through HTTPService"/>
                 
+                <j:Label text="This example loads its source code in the text code panel:"/>
+
                 <html:Pre height="400" percentWidth="100" style="background-color: white">
                     <js:beads>
                         <j:ScrollingViewport/>
                     </js:beads>
-                    <html:Code id="sourceCodeTextHolder"/>
+                    <html:Code id="sourceCodeMXMLText"/>
                 </html:Pre>
                 
-                <j:Button text="Retrieve source code from github" click="service.sourceCodeUrl = github_url"/>
+                <j:Label id="jsonData" multiline="true" html="This label show JSON data when loaded."/>
+
+                <j:Button text="Retrieve source code from github" emphasis="primary" click="getGithubContent(event)"/>
              </j:Card>
         </j:View>
     </j:initialView>
diff --git a/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/src/main/royale/services/GitHubService.as b/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/src/main/royale/services/GitHubService.as
index 666cf36..ad546bf 100644
--- a/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/src/main/royale/services/GitHubService.as
+++ b/examples/blog/BE0011_Loading_Github_external_data_through_HTTPService/src/main/royale/services/GitHubService.as
@@ -34,13 +34,9 @@ package services
          * constructor
          */
         public function GitHubService():void
-        {
-            // this header makes gihub serve the raw code instead of base64 encoded data
-            var header:HTTPHeader = new HTTPHeader('accept', 'application/vnd.github.VERSION.raw');
-            
+        {    
             service = new HTTPService();
-			service.headers.push(header);
-			service.addEventListener("complete", completeHandler);
+            service.addEventListener("complete", completeHandler);
         }
 
         /**
@@ -56,7 +52,6 @@ package services
             dispatchEvent(new Event("dataReady"));
         }
 
-        //example = "https://api.github.com/repos/apache/royale-asjs/contents/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml";
         private var _sourceCodeUrl:String = null;
         /**
          * The source code url we want to retrieve
@@ -67,17 +62,47 @@ package services
         }
         public function set sourceCodeUrl(value:String):void
         {
-        	_sourceCodeUrl = value;
+            _sourceCodeUrl = value;
             service.url = sourceCodeUrl;
-            service.send();
         }
 
         /**
-         * data holds the resulting text code to show
+         * json return the retrieved GitHub JSON Object
+         */
+        public function get json():Object
+        {
+            return service.json;
+        }
+
+        /**
+         * jsonToString return the retrieved GitHub JSON Object as String
+         */
+        public function get jsonToString():String
+        {
+            return service.data;
+        }
+
+        /**
+         * decode and return the base 64 content (real source code)
+         */
+        public function get sourceCode():String
+        {
+            COMPILE::JS
+            {
+                return atob(service.json.content);
+            }
+            COMPILE::SWF
+            {
+                return "";// to implement for SWF
+            }
+        }
+        
+        /**
+         * trigger the HTTPService to retrieve the GitHub data
          */
-        public function get data():String
+        public function getContent():void
         {
-        	return service.data;
+        	service.send();
         }
 	}
 }