cancel
Showing results for 
Search instead for 
Did you mean: 

Flex3 Corelib JSON issues

alexr
Champ in-the-making
Champ in-the-making
I am testing webscripts (JSON) on Alfresco Community 2.1

I downloaded the ascorelib3 corelib90 (containing JSON funcionality) from http://code.google.com/p/as3corelib/ and configured it for Flexbuilder 3. However
for some reason this corelib doesn't seem to work with Flex3?
Does anybody have a corelib.swc compatible with flexbuilder3 that I can use to test my Alfresco JSON webscripts against and any tips on how
to make this work.

The following JSONExample application:

<?xml version="1.0" encoding="utf-8"?>

<!–
Adobe Systems Incorporated(r) Source Code License Agreement
Copyright© 2005 Adobe Systems Incorporated. All rights reserved.
   
Please read this Source Code License Agreement carefully before using
the source code.
   
Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable copyright license, to reproduce,
prepare derivative works of, publicly display, publicly perform, and
distribute this source code and such derivative works in source or
object code form without any attribution requirements.
   
The name "Adobe Systems Incorporated" must not be used to endorse or promote products
derived from the source code without prior written permission.
   
You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
against any loss, damage, claims or lawsuits, including attorney's
fees that arise or result from your use or distribution of the source
code.
   
THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
–>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
   layout="absolute"
   creationComplete="service.send()">
   
   <mxSmiley Frustratedcript>
      <![CDATA[
         import mx.collections.ArrayCollection;
         import mx.rpc.events.ResultEvent;
         import com.adobe.serialization.json.JSON;
         
         private function onJSONLoad(event:ResultEvent):void
         {
            var rawDataSmiley Frustratedtring = String(event.result);
            var arr:Array = (JSON.decode(rawData) as Array);
            
            var dp:ArrayCollection = new ArrayCollection(arr);
            
            grid.dataProvider = dp;
            
         }
      ]]>
   </mxSmiley Frustratedcript>
   
   <mx:HTTPService
      id="service"
      resultFormat="text"
      url="http://weblogs.macromedia.com/mesh/mashedpotato.json"
      result="onJSONLoad(event)" />
   
   <mxSmiley Very HappyataGrid id="grid" right="10" left="10" top="10" bottom="10">
      <mx:columns>
         <mxSmiley Very HappyataGridColumn headerText="Service" dataField="src"/>
         <mxSmiley Very HappyataGridColumn headerText="Title" dataField="title"/>
      </mx:columns>
   </mxSmiley Very HappyataGrid>
   
</mx:Application>




=============================================================

Throws the following errors:

Error: Unexpected < encountered
   at com.adobe.serialization.json::JSONTokenizer/parseError()[C:\Documents and Settings\mchamber\My Documents\src\flashplatform\projects\corelib\trunk\src\actionscript3\com\adobe\serialization\json\JSONTokenizer.as:492]
   at com.adobe.serialization.json::JSONTokenizer/getNextToken()[C:\Documents and Settings\mchamber\My Documents\src\flashplatform\projects\corelib\trunk\src\actionscript3\com\adobe\serialization\json\JSONTokenizer.as:171]
   at com.adobe.serialization.json::JSONDecoder/nextToken()[C:\Documents and Settings\mchamber\My Documents\src\flashplatform\projects\corelib\trunk\src\actionscript3\com\adobe\serialization\json\JSONDecoder.as:88]
   at com.adobe.serialization.json::JSONDecoder()[C:\Documents and Settings\mchamber\My Documents\src\flashplatform\projects\corelib\trunk\src\actionscript3\com\adobe\serialization\json\JSONDecoder.as:63]
   at com.adobe.serialization.json::JSON$/decode()[C:\Documents and Settings\mchamber\My Documents\src\flashplatform\projects\corelib\trunk\src\actionscript3\com\adobe\serialization\json\JSON.as:81]
   at JSONExample/onJSONLoad()[C:\Documents and Settings\Administrator\My Documents\Flex Builder 3\JSONExample\src\JSONExample.mxml:51]
   at JSONExample/__service_result()[C:\Documents and Settings\Administrator\My Documents\Flex Builder 3\JSONExample\src\JSONExample.mxml:65]
   at flash.events::EventDispatcher/dispatchEventFunction()
   at flash.events::EventDispatcher/dispatchEvent()
   at mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\http\mxml\HTTPService.as:275]
   at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:191]
   at mx.rpc::Responder/result()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\Responder.as:41]
   at mx.rpc::AsyncRequest/acknowledge()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74]
   at DirectHTTPMessageResponder/completeHandler()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:381]
   at flash.events::EventDispatcher/dispatchEventFunction()
   at flash.events::EventDispatcher/dispatchEvent()
   at flash.net::URLLoader/onComplete()





=============================================================
Kind Regards,

Alex
3 REPLIES 3

stevereiner
Champ in-the-making
Champ in-the-making
If you want to use Flex with Alfresco, you should start with the the small flex framework from the alfresco SVN  ( head/root/modules/flex-sdk/framework) to provide login/logout/webscript infrastructure, and ACE  ( head/root/modules/ace ) to provide an example of login/logout/search using the framework. Thats how I started. 

I am pretty far along with both a Flex based Alfresco client and a Flex+AIR Alfresco client.  I am using Flex 3.0, AIR 1.0, and the latest Alfresco 2.9.0C_dev via javascript webscripts.  From google code: I didn't use corelib, I did use flexlib for tabs.

The alfresco flex-sdk works fine for the object result format of the flex mx.rpc.http.HTTPService. I had to change org.alfresco.framework.service.webscript.WebScriptService.as to work with the e4x result format of mx.rpc.http.HTTPService.

Steve Reiner

http://www.integratedsemantics.com

stevereiner
Champ in-the-making
Champ in-the-making
On as3corelib to decode JSON with text format from flex HTTPService
1. Noticed problem parsing "<" in the error stack
2. latest build (.90) of as3corelib is old (March 19, 2007)
3. you could try slightly newer code (last change may 27, 2007) in src/com/adobe/serialization/json/*.* via
http://code.google.com/p/as3corelib/source/browse
or svn checkout http://as3corelib.googlecode.com/svn/trunk/ as3corelib-read-only
4. noticed some json encode/decode issues at http://code.google.com/p/as3corelib/issues/list

P.S.
if using alfresco flex-sdk with HTTPService with non object result format, a quick workaround in
src/org/alfresco/framework/service/webscript/WebScriptService.as  onResultEvent() is to change
from:   if (event.result.response != null &&
to:       if (this.resultFormat == "object" && 
               event.result.response != null &&
(more changes would be needed to have status code checking for other formats)

New: Forgot to mention that in each of my ActionScript service classes set  webScript.resultFormat ="e4x";   (where webScript is instance of org.alfresco.framework.service.webscript.WebScriptService, WebScriptService extends  flex HTTPService)

Steve

alexr
Champ in-the-making
Champ in-the-making
Thank you Steve,

The webservice URL i tested was broken (server down). I tested another json webservice (Yahoo) and my mxml application worked. So Flexbuilder
and the corelib seems to be configured ok.
I have however posted a new question about json and the folder.get webscript in this forum branch.

Kind regards,

Alex
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.