Better Adobe Flex and AIR applications with AJAX


Published on

This is my presentation at the 360Flex Europe conference.

Published in: Technology, Business
  • #Ajax Ajax Tutorial (Videos and Books)Just$7.95
    Are you sure you want to  Yes  No
    Your message goes here
  • Ajax and flex information is very interesting and slide presentation is also very good.
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Better Adobe Flex and AIR applications with AJAX

  1. 360Flex Europe Marco Casario CTO – Comtaste
  2. Who I am 360Flex Europe <ul><li>CTO of Comtaste , RIA Development, Consulting and Training firm </li></ul><ul><ul><ul><ul><li> </li></ul></ul></ul></ul><ul><li>My Books </li></ul><ul><ul><ul><li>Flex Solutions: Essential Techniques for Flex 2 and Flex 3 Developers </li></ul></ul></ul><ul><ul><ul><li>Advanced AIR Applications </li></ul></ul></ul><ul><li>My Blog and my contacts </li></ul><ul><ul><ul><ul><li> </li></ul></ul></ul></ul><ul><ul><ul><ul><li> </li></ul></ul></ul></ul>
  3. Agenda 360Flex Europe <ul><li>We’ll talk about the possibility to use a mix of AJAX and Flex in your applications </li></ul><ul><li>I’ll talk about : </li></ul><ul><ul><ul><li>Why use Flex and AJAX together </li></ul></ul></ul><ul><ul><ul><li>Benefits of using one or the other technology (and both) </li></ul></ul></ul><ul><ul><ul><li>How to exchange data between AJAX and Flex </li></ul></ul></ul><ul><ul><ul><li>Communicating with the wrapper </li></ul></ul></ul><ul><ul><ul><li>Using the ExternalInterface class </li></ul></ul></ul><ul><ul><ul><li>Using the Flex AJAX Bridge classes </li></ul></ul></ul><ul><ul><ul><li>When to use the FABridge </li></ul></ul></ul><ul><ul><ul><li>What we’ve learned in our project’s development </li></ul></ul></ul><ul><ul><ul><li>AJAX and Flex Best Practice </li></ul></ul></ul><ul><ul><ul><li>Using the Data Services </li></ul></ul></ul><ul><ul><ul><li>Using the AJAX Data Services </li></ul></ul></ul><ul><li>We will move very quickly  A lot of things to show and share! </li></ul>
  4. GOAL Why use AJAX and Flex together AJAX + Flex 360Flex Europe <ul><li>AJAX and Flex are powerful tools. You can use them together to : </li></ul><ul><ul><li>If you have an AJAX application and you want to add rich UI controls and functionalities </li></ul></ul><ul><ul><li>Overcome the limit of the HTML UI controls </li></ul></ul><ul><ul><li>Reduce the time of testing your Flex stuff on different browsers and different OSs </li></ul></ul>
  5. GOAL Some of the limits of AJAX-oriented apps AJAX + Flex 360Flex Europe <ul><li>AJAX could require a consistent time in testing and debugging </li></ul><ul><ul><li>Choosing a commercial AJAX solution means adopting a proprietary framework and tool </li></ul></ul><ul><ul><li>The AJAX market is very fragmented </li></ul></ul><ul><ul><li>The community is big but has caused a lot of confusion. There’s no official voice to follow. </li></ul></ul>
  6. GOAL Some of the limits of Flex-oriented apps AJAX + Flex 360Flex Europe <ul><ul><li>The learning curve for Flex is higher than HTML+JavaScript </li></ul></ul><ul><ul><li>Flex is tied to Flash Player (no DHTML) </li></ul></ul><ul><ul><li>The Flash Player is not open but is property of Adobe </li></ul></ul>
  7. GOAL So why don’t use them together ? AJAX + Flex 360Flex Europe
  8. GOAL Are Flash and AJAX real enemy ? AJAX + Flex 360Flex Europe
  9. GOAL The story ended this way: AJAX + Flex 360Flex Europe The long spike protruding from Ajax impales Ming with an ooze of green blood and Flash advances upon the dying villain with a golden scimitar
  10. GOAL FLASH and AJAX defeated the Evil. Why don’t use them together in your development? AJAX + Flex 360Flex Europe
  11. GOAL What we’ve learned using Flex and AJAX together Design Patterns 360Flex Europe YouThruBiz is a Rich Internet Application that will help you shortlist the right candidates for the job using customized multimedia job interviews and e-resumes. Highly effective recruitment and powerful assessment, in less time
  12. GOAL What we’ve learned using Flex and AJAX together Design Patterns 360Flex Europe is a platform which is accessible on the internet and on mobile terminals for all those who love Italy for its enchanting locations, for its excellent cuisine and exceptional hotels
  13. GOAL What we’ve learned using Flex and AJAX together Design Patterns 360Flex Europe FlexGala is the official Adobe User Group dedicated to RIA development using Flex 3, AIR and ActionScript 3.
  14. GOAL Less is More. AJAX + Flex 360Flex Europe
  15. GOAL Communicating between AJAX and Flex AJAX + Flex 360Flex Europe <ul><ul><li>A Flex widget is loaded in a browser within a wrapper(an HTML page with some JavaScript) </li></ul></ul><ul><ul><li>There are different ways to exchange data between an Flex application and the AJAX page: </li></ul></ul><ul><ul><li>using the flashVars properties, </li></ul></ul><ul><ul><li>querying string parameters, </li></ul></ul><ul><ul><li>using the navigateToURL() method </li></ul></ul><ul><ul><li>using the ExternalInterface class </li></ul></ul>
  16. GOAL Using the FlashVars properties AJAX + Flex 360Flex Europe <ul><ul><li>The flashVars properties are declared inside the HTML page (the wrapper) and read in the Flex application at run time: </li></ul></ul><object id='mySwf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='' height='100%' width='100%'> <param name='src' value='FlashVarTest.swf'/> <param name='flashVars' value='firstName=Marco&lastName=Casario'/> <embed name='mySwf' src='FlashVarTest.swf' pluginspage='' height='100%' width='100%' flashVars='firstName=Marco&lastName=Casario'/> </object>
  17. GOAL Using URL fragments AJAX + Flex 360Flex Europe <ul><ul><li>You can access variables on the query string without providing additional code: </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li>In your Flex app to access the values you use the Application.application.parameters object: </li></ul></ul><ul><ul><li>myName:String = new String(Application.application.parameters. firstName); </li></ul></ul>
  18. GOAL Using URL fragments AJAX + Flex 360Flex Europe <ul><ul><li>The BrowserManager also provides a method of accessing values from a URL inside your Flex application. </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li>To convert these parameters to an object, you get the URL and then use the URLUtil class's stringToObject() method. </li></ul></ul>
  19. GOAL Using flashVars AJAX + Flex 360Flex Europe DEMO
  20. GOAL Using the navigateToURL() method AJAX + Flex 360Flex Europe <ul><ul><li>The navigateToURL() method (part of the package) loads a document from a specific URL into a window. </li></ul></ul><ul><ul><li>But it also allows you to pass variables to another application at a defined URL. </li></ul></ul><ul><ul><li>So you can use this method to call JavaScript functions in the HTML page that encloses a Flex application. </li></ul></ul>
  21. GOAL Using the navigateToURL() method AJAX + Flex 360Flex Europe <ul><li>The navigateToURL() method has the following syntax: </li></ul><ul><ul><li>navigateToURL(request:URLRequest, window:String):void </li></ul></ul><ul><ul><ul><ul><ul><li>request: is a URLRequest object that specifies the destination. </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>window: specifies whether to launch a new browser window or load the new URL into the current window. </li></ul></ul></ul></ul></ul>
  22. GOAL Using the navigateToURL() method AJAX + Flex 360Flex Europe <ul><ul><li>You can use the navigateToURL() method to invoke JavaScript functions: </li></ul></ul><ul><ul><li>//in Flex var u:URLRequest = new URLRequest(&quot;javascript:catchClick('&quot; </li></ul></ul><ul><ul><li>+ eName + &quot;','&quot; + eType + &quot;')&quot;); </li></ul></ul><ul><ul><li>navigateToURL(u,&quot;_self&quot;); </li></ul></ul><ul><ul><li>//On the HTML page </li></ul></ul><ul><ul><li><SCRIPT LANGUAGE=&quot;JavaScript&quot;> </li></ul></ul><ul><ul><li>function catchClick(name, type) { </li></ul></ul><ul><ul><li>alert(name + &quot; triggered the &quot; + type + &quot; event.&quot;); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li></SCRIPT> </li></ul></ul>
  23. GOAL Using the ExternalInterface API AJAX + Flex 360Flex Europe <ul><ul><li>The ExternalInterface is part of the flash.external package </li></ul></ul><ul><ul><li>This class allows developers to pass data from the Flex application to the enclosing HTML page, process it, and then pass it back to the Flex application. </li></ul></ul><ul><ul><li>Moreover you can call any JavaScript method on the wrapper, pass parameters, and get a return value. </li></ul></ul>
  24. GOAL Calling JavaScript methods from Flex AJAX + Flex 360Flex Europe <ul><ul><li>Using the static call() method of the ExternalInterface API: </li></ul></ul><ul><ul><li>[, arg1, ...]):Object; </li></ul></ul><ul><ul><li>Using the call() method requires that the embedded Flex application have a ID name declared in the wrapper (on the <object> tag and a name attribute on the <embed> tag) </li></ul></ul>
  25. GOAL Accessing Flex from JavaScript AJAX + Flex 360Flex Europe <ul><ul><li>You can call Flex methods from JavaScript using a local Flex function to the list by using the addCallback(): </li></ul></ul><ul><ul><li>addCallback(function_name:String, closure:Function):void </li></ul></ul>
  26. GOAL Accessing Flex from JavaScript AJAX + Flex 360Flex Europe <ul><ul><li>public function myFunc(s:String):void { // whatever you want} </li></ul></ul><ul><ul><li>public function initApp():void { </li></ul></ul><ul><ul><li>ExternalInterface.addCallback(&quot;myFlexFunction&quot;,myFunc); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li><SCRIPT LANGUAGE=&quot;JavaScript&quot;> </li></ul></ul><ul><ul><li>function callApp() { </li></ul></ul><ul><ul><li>window.document.title = document.getElementById(&quot;newTitle&quot;).value; </li></ul></ul><ul><ul><li>mySwf.myFlexFunction(window.document.title); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li></SCRIPT> </li></ul></ul>
  27. GOAL Calling JavaScript methods from Flex AJAX + Flex 360Flex Europe <ul><ul><li>DEMO </li></ul></ul><ul><ul><li>Flash Player have strict security in place to prevent cross-site scripting. By default, you cannot call script on an HTML page if the HTML page is not in the same domain as the Flex application. </li></ul></ul>
  28. GOAL ExternalInterface API security AJAX + Flex 360Flex Europe <ul><ul><li>Restrictions: </li></ul></ul><ul><ul><li>By default, scripts on the HTML page can communicate only with ActionScript in a Flex application if the page and the application are in the same domain. </li></ul></ul><ul><ul><li>Using the allowScriptAccess parameter (an HTML parameter) you can determine whether your Flex application can call JavaScript in the HTML page, and it applies to all functions on the page. </li></ul></ul>
  29. GOAL ExternalInterface API security AJAX + Flex 360Flex Europe <ul><ul><li>Restrictions: </li></ul></ul><ul><ul><li><object id=‘myName' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='' </li></ul></ul><ul><ul><li>allowScriptAccess='always' </li></ul></ul><ul><ul><li>height='100%' width='100%'> </li></ul></ul>
  30. GOAL ExternalInterface API security AJAX + Flex 360Flex Europe <ul><ul><li>Valid values of the allowScriptAccess parameter: </li></ul></ul><ul><ul><li>Never: The call() method fails. </li></ul></ul><ul><ul><li>sameDomain: The call() method succeeds if the calling application is from same domain as the HTML page. </li></ul></ul><ul><ul><li>Always: The call() method succeeds, regardless of whether the calling application is in the same domain as the HTML page. </li></ul></ul>
  31. GOAL ExternalInterface API security AJAX + Flex 360Flex Europe <ul><ul><li>The following browsers support the ExternalInterface API: </li></ul></ul><ul><ul><li>All versions of Internet Explorer for Windows (5.0 and later) </li></ul></ul><ul><ul><li>Embedded custom ActiveX containers, such as a desktop application embedding Adobe Flash Player ActiveX control </li></ul></ul><ul><ul><li>Any browser that supports the NPRuntime interface (which currently includes the following browsers):Firefox 1.0 and later, Mozilla 1.7.5 and later,Netscape 8.0 and later, Safari 1.3 and later </li></ul></ul>
  32. GOAL ExternalInterface API security AJAX + Flex 360Flex Europe <ul><ul><li>To check the browser’s support of the ExternalInterface API you can use the available property. </li></ul></ul><ul><ul><li>The available property is a Boolean value that is true if the browser supports the ExternalInterface API and false if the browser does not. </li></ul></ul>
  33. GOAL The Flex AJAX Bridge AJAX + Flex 360Flex Europe <ul><ul><li>The Flex Ajax Bridge (FABridge) is a small, unobtrusive code library that you can insert into a Flex widget, or an empty SWF file to expose it to scripting in the web browser. It’s based on the ExternalInterface API. </li></ul></ul><ul><ul><li>It will save you a lot of time. </li></ul></ul><ul><ul><li>Using the library anything you can do with ActionScript, you can do with JavaScript. </li></ul></ul>
  34. GOAL When to use the Flex AJAX Bridge AJAX + Flex 360Flex Europe <ul><ul><li>The FABridge library is useful in the following situations: </li></ul></ul><ul><ul><li>You want to use a rich Flex component in an Ajax application but do not want to write a lot of Flex code. </li></ul></ul><ul><ul><li>If you wrap the component in a FABridge-enabled stub application, you can script it entirely from JavaScript, including using JavaScript generated remotely by the server. </li></ul></ul>
  35. GOAL When to use the Flex AJAX Bridge AJAX + Flex 360Flex Europe <ul><ul><li>The FABridge library is useful in the following situations: </li></ul></ul><ul><ul><li>You have only one or two people on your team who know Flex. The FABridge library lets everyone on your team use the work produced by one or two Flex specialists. </li></ul></ul><ul><ul><li>You are building an integrated rich Internet application (RIA) with Flex and Ajax portions.Although you could build the integration yourself using ExternalInterface, you might find it faster to start with the FABridge. </li></ul></ul>
  36. GOAL Use the Flex AJAX Bridge AJAX + Flex 360Flex Europe <ul><li>Add src folder to the ActionScript classpath of your Flex application </li></ul><ul><li>Invoke the MXML component intoyour Flex Application : <fab:FABridge xmlns:fab=&quot;bridge.*&quot; /> </li></ul><ul><li>access your application instance from JavaScript flexApp = FABridge.FlexBridgeName.root(); </li></ul>
  37. GOAL Wait for initialization AJAX + Flex 360Flex Europe <ul><li>Before running the initialization code on a Flex file, you must wait for it to download and initialize first. Register a callback to be invoked when the movie is initialized </li></ul><ul><li>function initMaxPrice(maxPrice) </li></ul><ul><li>{ </li></ul><ul><li>var initCallback = function() </li></ul><ul><li>{ </li></ul><ul><li>var flexApp = FABridge.flash.root(); </li></ul><ul><li>flexApp.getMaxPriceSlider().setValue(maxPrice); </li></ul><ul><li>} </li></ul><ul><li>FABridge.addInitializationCallback(&quot;flash&quot;,initCallback); </li></ul><ul><li>} </li></ul>
  38. GOAL Get and set value of a property AJAX + Flex 360Flex Europe <ul><li>To get the value of a property: var appWidth = flexApp.getWidth(); var maxPrice = flexApp.getMaxPriceSlider().getValue(); </li></ul><ul><li>To set the value of a property from JavaScript, call the setPropertyName() function </li></ul><ul><li>flexApp.getMaxPriceSlider().setValue(newMaxPrice); flexApp = FABridge.flash.root(); </li></ul>
  39. GOAL Get and set value of a property AJAX + Flex 360Flex Europe <ul><li>You call object methods directly, just as you would from ActionScript flexApp.getShoppingCart().addItem(&quot;Antique Figurine&quot;, 12.99); </li></ul><ul><li>You also pass functions, such as event handlers, from JavaScript to ActionScript </li></ul><ul><li>var maxPriceCallback = function(event) </li></ul><ul><li>{ </li></ul><ul><li>document.maxPrice = event.getNewValue(); </li></ul><ul><li>} </li></ul><ul><li>flexApp.getMaxPriceSlider().addEventListener(&quot;change&quot;, maxPriceCallback); </li></ul><ul><li>flexApp.getMaxPriceSlider().setValue(newMaxPrice); </li></ul>
  40. GOAL Memory management AJAX + Flex 360Flex Europe <ul><li>The FABridge uses a reference counting mechanism in order to provide automatic memory management </li></ul><ul><li>Objects created from the JavaScript side are kept in memory unless the memory is manually released. </li></ul><ul><li>Events and other ActionScript-initiated objects are destroyed as soon as the corresponding JavaScript function that handles them directly completes its execution. </li></ul><ul><li>You manually call the addRef() method for an object to have it remain available, or call the release() method to decrease its reference </li></ul>
  41. GOAL Limitations of the FABridge AJAX + Flex 360Flex Europe <ul><li>The FABridge library has been tested on: </li></ul><ul><ul><li>Mozilla Firefox 2 (Windows and Linux), </li></ul></ul><ul><ul><li>Microsoft Internet Explorer 6, </li></ul></ul><ul><ul><li>Opera 9, </li></ul></ul><ul><ul><li>Apple Safari 2.0.4 </li></ul></ul><ul><li>For performance reasons, when an anonymous object is sent from ActionScript to JavaScript, the bridge assumes it contains only primitives, arrays, and other anonymous objects, and no strongly typed objects or methods. Instances or methods sent as part of an anonymous object are not bridged correctly. </li></ul>
  42. GOAL Use the Flex AJAX Bridge AJAX + Flex 360Flex Europe <ul><ul><li>DEMO </li></ul></ul>
  43. GOAL Using the FAVideo Library AJAX + Flex 360Flex Europe The Adobe Flash Ajax Video (FAVideo) component is a small, open source Flash component that you can use to provide video playback within an Ajax application. It exposes all of the formatting and video playback controls necessary to build a video player customized entirely using HTML and Javascript.
  44. GOAL When use the FAVideo Library AJAX + Flex 360Flex Europe * When you want to add media capabilities to your AJAX application * You need a compact and small video playback solution. The FAVideo component is only 15k * You want full creative control over presentation of the video within your application.
  45. GOAL Getting Started with the FAVideo Library AJAX + Flex 360Flex Europe Import the Javascript libraries you need to use the dependencies FAVideo library : <script src=&quot;FAVideo.js&quot; type=&quot;text/javascript&quot;></script> <script src=&quot;AC_RunActiveContent.js“ type=&quot;text/javascript&quot;></script>
  46. GOAL Getting Started with the FAVideo Library AJAX + Flex 360Flex Europe Istantiate the video player and set the start up properties : player = new FAVideo(&quot;playerDiv&quot;); player.stop(); isPlaying = false; isMuted = false; oldVolume = 50; playingVideoId = null;
  47. GOAL Getting Started with the FAVideo Library AJAX + Flex 360Flex Europe Register the playheadUpdate listener to programmatically update the timing via JavaScript : player.addEventListener(&quot;playheadUpdate&quot;, this, playheadUpdate); function playheadUpdate(event) { if(playingVideoId != null) if(document.getElementById(&quot;videoList_div&quot;+playingVideoId) != null) document.getElementById(&quot;videoList_div&quot;+playingVideoId).innerHTML = Math.floor(parseFloat(event.playheadTime)) + &quot;/&quot; + Math.floor(parseFloat(event.totalTime)); }
  48. GOAL Using the FAVideo Library AJAX + Flex 360Flex Europe DEMO
  49. GOAL Using 2 client side technologies it’s essential to find a practical way to debug your application. Flex and AJAX Best Practice 360Flex Europe Debug Flex and AJAX
  50. GOAL Monitore the network traffic could be crucial in many contexts. 360Flex Europe Monitoring the network traffic TraceTarget
  51. GOAL This class provides a logger target that uses the trace() method to output log messages 360Flex Europe The TraceTarget class TraceTarget
  52. GOAL 360Flex Europe Using Firebug Extension TraceTarget
  53. GOAL <ul><li>You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page: </li></ul><ul><li>Monitor network activity </li></ul><ul><li>Debug and profile JavaScript </li></ul><ul><li>Quickly find errors </li></ul><ul><li>Explore the DOM </li></ul><ul><li>Logging for JavaScript </li></ul><ul><li>Execute JavaScript on the fly </li></ul>360Flex Europe TraceTarget Using Firebug Extension
  54. GOAL <ul><li>TThe Logging API of Flex SDK allows you to write and send messages to an output created by the developer. </li></ul><ul><li>TThey consists of three principal components: </li></ul><ul><ul><li>the Logger object, </li></ul></ul><ul><ul><li>the log target, </li></ul></ul><ul><ul><li>and the destination. </li></ul></ul>360Flex Europe Debug using the Logging APIs TraceTarget
  55. GOAL To use the Logging API and send the messages to the Flash Player Debug, you must define the log target and add it to the Log object: myLogTarget:TraceTarget = new TraceTarget(); Log.addTarget(myLogTarget); Logging APIs 360Flex Europe Debug using the Logging APIs
  56. GOAL Then, using the getLogger() method of the Log object, you can send a message to the file that you intend to debug: Log.getLogger(&quot;myMXMLfileOrClass&quot;).info(&quot;My message&quot;); 360Flex Europe Debug using the Logging APIs Logging APIs
  57. GOAL <ul><li>To filter a message with the Log class, a category and a level properties are used. </li></ul><ul><li>A category is used to filter messages sent from a logger. It's a simple String. </li></ul><ul><li>A level provides filtering options for the message defining the constants on the LogEventLevel class. </li></ul>360Flex Europe Debug using the Logging APIs Logging APIs
  58. GOAL 360Flex Europe Debug using the Logging APIs Logging APIs
  59. GOAL You can print all the messages passed to the global trace() method in an external file called flashlog.txt. Create and configure the mm.cfg file (usually located in driveDocuments and Settingsuser_name) as follow: TraceOutputFileName=c:/logs/flashlog.txt ErrorReportingEnable=1 TraceOutputFileEnable=1 MaxWarnings=0 Troubleshooting tips for flashlog.txt not being generated 360Flex Europe Debug with the flashlog.txt file Logging APIs
  60. GOAL What we’ve learned using Flex and AJAX together Design Patterns 360Flex Europe In a mixed enviroment where different developers have to communicate together, it’s crucial to use the same language. If you want to save time,it worths the use of the Design Patterns in Flex and Javascript.
  61. GOAL Architecture your code Design Patterns 360Flex Europe <ul><li>Design patterns are a general reusable solutions to a commonly occurring problem in software design. </li></ul><ul><ul><li>DP can speed up the development process by providing tested, proven development paradigms. </li></ul></ul><ul><ul><li>DP improves code readability for and between developers </li></ul></ul>
  62. GOAL Create a View Helper Design Patterns 360Flex Europe A view helper contains formatting code, delegating its processing responsibilities to its helper classes, implemented as Actionscript classes. Helpers also store the view's intermediate data model and serve as business data adapters.
  63. GOAL Elements of a View Helper Design Patterns 360Flex Europe A View Helper consists in an ActionScript class that encapsulates business logic in a helper instead of a view, making our application more modular by facilitating component re-use.
  64. GOAL Elements of a View Helper Design Patterns 360Flex Europe <h:UploadHelper id=&quot;uploadHelper&quot; /> package com.fitc { import; import; ........ public class UploadHelper {} }
  65. GOAL Create a Model Locator Design Patterns 360Flex Europe The Model Locator pattern defines a component that is responsible for centralizing data in an application. When the data is updated in ModelLocator, all view components binded to the model, update themselves to render the new data.
  66. GOAL Elements of a Model Locator Design Patterns 360Flex Europe A Model Locator is an ActionScript class that uses the Singleton pattern. This pattern has a method that creates a new instance of the class if one does not exist. If an instance already exists, it simply returns a reference to that object.
  67. GOAL The AJAX Data Services AJAX + Flex 360Flex Europe <ul><ul><li>Ajax Data Services is a JavaScript library that lets Ajax developers access the messaging and data management capabilities of Livecycle Data Services directly from JavaScript. </li></ul></ul><ul><ul><li>It lets you use Flex clients and Ajax clients that share data in the same messaging application or distributed data application. </li></ul></ul>
  68. GOAL AJAX Data Services vs. Flex AJAX Bridge AJAX + Flex 360Flex Europe <ul><ul><li>They’re are based on the same core library </li></ul></ul><ul><ul><li>The AJAX Data Services take the advantages of using the enterprise features of the Data Services </li></ul></ul><ul><ul><li>The AJAX Data Services are the best solution to integrate AJAX in Enterprise Rich Internet Applications </li></ul></ul>
  69. GOAL The Livecycle Data Services AJAX + Flex 360Flex Europe <ul><ul><li>Livecycle Data Services are part of the Livecycle Enterprise Suite (ES) </li></ul></ul><ul><ul><li>They are a J2EE application (3 WAR files) deployed in a J2EE application server </li></ul></ul><ul><ul><li>They are oriented to Enterprise applications where intensive data streams exist </li></ul></ul>
  70. GOAL The Livecycle Data Services AJAX + Flex 360Flex Europe <ul><ul><li>Create data-intensive RIAs with less code </li></ul></ul><ul><ul><li>Enable collaboration, offline Adobe Integrated Runtime, and real-time data streaming applications </li></ul></ul><ul><ul><li>Generate PDF documents based on template </li></ul></ul><ul><ul><li>Integrate your Flex application in complex J2EE architecture using Spring, Hibernate adaptors </li></ul></ul>
  71. GOAL The Livecycle Data Services Schema AJAX + Flex 360Flex Europe
  72. GOAL Data Services Features AJAX + Flex 360Flex Europe <ul><ul><li>Client-server synchronization </li></ul></ul><ul><ul><li>Conflict resolution: The Data Management Services feature provides a conflict resolution API for detecting and handling data synchronization conflicts and ensuring the integrity of distributed data by limiting further changes until conflicts are resolved. </li></ul></ul><ul><ul><li>Automatic system for Data paging </li></ul></ul>
  73. GOAL Data Services Features AJAX + Flex 360Flex Europe <ul><ul><li>Open adapter architecture: Data Services ES provides an open adapter architecture to easily integrate with JMS, Hibernate, EJB, and other data persistence mechanisms. </li></ul></ul><ul><ul><li>SQL adapter: this adapter to automatically detect changes made on the client, paging from server to client, and conflict detection. </li></ul></ul>
  74. GOAL Data Services Features AJAX + Flex 360Flex Europe <ul><ul><li>Publish and subscribe messaging: Publish and subscribe to message topics in real time </li></ul></ul><ul><ul><li>Real time Data Push: The messaging and real time infrastructure enables collaboration and data push applications to be built in a scalable and reliable manner while preserving the lightweight web deployment model. </li></ul></ul>
  75. GOAL Benefits of using the AJAX Data Services AJAX + Flex 360Flex Europe <ul><ul><li>Many Ajax applications are taking on the responsibilities of round tripping data. </li></ul></ul><ul><ul><li>Using Ajax Data Services, developers are able to build sophisticated applications that more deeply integrate with backend data and services. Flex Data Services provides integrated publish subscribe messaging, real-time streaming data, and a rich data management API that dramatically simplifies the development of rich Internet applications. </li></ul></ul><ul><ul><li>Adding Flex Data Management Services to these applications adds the benefits of pushed updates, conflict management, lazy loading, and direct integration with back end domain models. </li></ul></ul>
  76. GOAL The AMF3 format AJAX + Flex 360Flex Europe <ul><ul><li>Action Message Format (AMF) is a compact binary format that is used to serialize ActionScript object graphs. </li></ul></ul><ul><ul><li>Once serialized an AMF encoded object graph may be used to persist and retrieve the public state of an application across sessions or allow two endpoints to communicate through the exchange of strongly typed data. </li></ul></ul><ul><ul><li>See </li></ul></ul>
  77. GOAL Installing Livecycle DS AJAX + Flex 360Flex Europe <ul><ul><li>You can install LCDS in two different flavours : </li></ul></ul><ul><ul><li>LiveCycle Data Services with integrated JRun </li></ul></ul><ul><ul><li>LiveCycle Data Services J2EE web application </li></ul></ul><ul><ul><li>LiveCycle Data Services includes installers for the following platforms: </li></ul></ul><ul><ul><li>Windows </li></ul></ul><ul><ul><li>Solaris </li></ul></ul><ul><ul><li>Linux </li></ul></ul><ul><ul><li>Java (cross-platform installer) </li></ul></ul>
  78. GOAL Installing Livecycle DS AJAX + Flex 360Flex Europe <ul><ul><li>LiveCycle Data Services includes the following Web Application Archive (WAR) files: </li></ul></ul><ul><ul><li>flex.war - The primary Flex WAR file: use this as a starting point for building your LiveCycle Data Services application. </li></ul></ul><ul><ul><li>samples.war - Sample Flex applications. </li></ul></ul><ul><ul><li>flex-admin.war - Simple administration and monitoring application. </li></ul></ul>
  79. GOAL Configuring Data Management Service AJAX + Flex 360Flex Europe <ul><ul><li>To configure Data Management Services you’ll perfomr the following tasks : </li></ul></ul><ul><ul><li>configuring a Data Management Service destinations* </li></ul></ul><ul><ul><li>applying security to destinations </li></ul></ul><ul><ul><li>modifying logging settings </li></ul></ul><ul><ul><li>*A Data Management Service destination is the endpoint that you send data to and receive data from when you use the Data Management Service to provide data distribution and synchronization in your applications. </li></ul></ul>
  80. GOAL Configuring Data Management Service AJAX + Flex 360Flex Europe <ul><ul><li>You configure Data Management Service destinations in the data service section of the services-config.xml file </li></ul></ul><ul><ul><li>(located in the WEB_INF/flex directory of the web application that contains LCDS) </li></ul></ul>
  81. GOAL Configuring Data Management Service AJAX + Flex 360Flex Europe <ul><ul><li>A Data Management Service destination references one or more message channels that transport messages, and contains network- and server-related properties. Messages are transported to and from a destination over a message channel. </li></ul></ul><ul><ul><li>It can also reference a data adapter, which is server-side code that lets the destination work with data through a particular type of interface, such as a Java object. A data adapter provides the infrastructure for interacting with data resources. </li></ul></ul>
  82. GOAL Configuring Network elements AJAX + Flex 360Flex Europe <ul><li>The properties section of a destination definition contains a network section for defining client-server messaging behavior. </li></ul><ul><ul><li><destination id=&quot;contact&quot;> </li></ul></ul><ul><ul><li><properties> </li></ul></ul><ul><ul><li><network> </li></ul></ul><ul><ul><li><subscription-timeout-minutes>0</subscription-timeout-minutes> </li></ul></ul><ul><ul><li><paging enabled=&quot;true&quot; pageSize=&quot;10&quot;/> </li></ul></ul><ul><ul><li><throttle-inbound policy=&quot;ERROR&quot; max-frequency=&quot;500&quot;/> </li></ul></ul><ul><ul><li><throttle-outbound policy=&quot;REPLACE&quot; max-frequency=&quot;500&quot;/> </li></ul></ul><ul><ul><li></network> </li></ul></ul>
  83. GOAL Using Transaction AJAX + Flex 360Flex Europe Flex encapsulates client-committed operations in a single J2EE distributed transaction. All client data changes are handled as a unit. If one value cannot be changed, changes to all other values are rolled back. Distributed transactions are supported as long as your J2EE server provides support for J2EE transactions (JTA). <destination id=&quot;contact&quot;> <properties> <use-transactions>true</use-transactions> </properties> </destination>
  84. GOAL Data Services Security AJAX + Flex 360Flex Europe You can secure a destination by using a security constraint, which defines the access privileges for the destination. You use a security constraint to authenticate and authorize users before letting them access a destination. You can specify whether to use basic or custom authentication, and indicate the roles required for authorization.
  85. GOAL Using the AJAX Data Services AJAX + Flex 360Flex Europe To use AJAX Data Services in an AJAX application, you must include the following JavaScript libraries in script tags on the HTML page: * FDMSLib.js : contains the definition of LiveCycle DS APIs as JavaScript, and some utility methods for constructing and initializing Data Management Service objects. * FABridge.js : provides the FABridge library You must have the following ActionScript libraries to compile the SWF file: * *
  86. GOAL Using the AJAX Data Services AJAX + Flex 360Flex Europe Call the FDMSLib.load() to initialize the library. It creates the appropriate HTML to embed Flash Player and load the specified shim SWF file. After Flash Player loads the shim SWF file that contains the bridge, the specified callback is invoked to notify the application that Data Services are available and ready for use.
  87. GOAL Using the AJAX Data Services AJAX + Flex 360Flex Europe Load the FDMSBridge.swf file using JavaScript : <script> FDMSLibrary.load(&quot;/ajax/Products/FDMSBridge.swf&quot;, fdmsReady); </script> This SWF file is typically compiled using the application file
  88. GOAL Using the AJAX Data Services AJAX + Flex 360Flex Europe Once the bridge indicates that it is ready, we can proceed to load the data: function fdmsReady () { ... }
  89. GOAL Using the AJAX Data Services AJAX + Flex 360Flex Europe At this point the client constructs the appropriate Data Service objects and loads data from the server. The following example shows this sequence: function fdmsReady () { productS = new DataService(&quot;Products&quot;); productS.addEventListener(DataService.RESULT,productsResult); productS.addEventListener(DataService.FAULT, productFault); products = new ArrayCollection(); var token = productS.fill(products); token.set(&quot;operation&quot;, &quot;fill&quot;); }
  90. GOAL Using the AJAX Data Services AJAX + Flex 360Flex Europe Handle the result and fault event and make the data visible into the visual elements : function productsResult(event) { if (event.getToken().get(&quot;operation&quot;) == &quot;fill&quot;) { var htmlText = &quot;<table id='productTable'>&quot;; var product; for (var i=0; i<products.getLength(); i++) { product = products.getItemAt(i); htmlText += &quot;<tr><td>&quot;+ product.getName() + &quot;</td><td>&quot;+ product.category + &quot;</td></tr>&quot;; } htmlText += &quot;</table>&quot;; document.all[&quot;products&quot;].innerHTML = htmlText; } } }
  91. GOAL Adobe AIR 360Flex Europe Flex and AJAX on the desktop with AIR
  92. GOAL Adobe AIR 360Flex Europe Flex on the desktop with AIR Developing an AIR desktop application is very easy if you are an AJAX or a Flex developer.
  93. we make it RIA Marco Casario CTO – Comtaste
  94. FLEXGALA user group Matteo Ronchi Consultant – Comtaste [email_address]
  95. FLEXGALA Video tutorial viewer - read rss feeds from user group website - show available video tutorials - load video tutorials directly into application Written completely in HTML/css and Javascript to show Adobe Air powerful AJAX developments environment. Only open source or free tools and technologies used.
  96. technologies involved - Adobe Air SDK - HTML / css - Adobe Spry Framework - AJAX
  97. Aptana studio - Open source editor based on Eclipse - Javascript integrated development - HTML / Css Dom navigation - HTML internal rendering engine - Built-in integration with Adobe AIR sdk - code completion, based on AIRAliases.js - output console for tracing integrated - wizard for generate redistributable AIR applications
  98. AIRIntrospector: ajax debugging console inspired on Firebug console offers: - advanced tracing and data dumping options - interactive inspecting of HTML layout - XHR monitor - HTML / DOM navigator - access original and rendered source code of your pages
  99. Manage feeds with Spry Framework We used Spry functionalities to request Rss feed and parse it into our's HTML presentation layout: var rssData = new Spry . Data . XMLDataSet ( &quot;;, &quot;rss/channel/item&quot; ); In HTML feeds list is constructed using Spry Data binding functionalities: < div spry:region = &quot;rssData&quot;> < table width = &quot;100%&quot;> < tr spry:repeat = &quot;rssData&quot; spry:setrow = &quot;rssData&quot;> < td > < span class = &quot;header&quot;> {title} </ span >< br /> < span class = &quot;date&quot;> {pubDate} </ span > </ td > </ tr > </ table > </ div >
  100. Application XML descriptor file <?xml version= &quot;1.0&quot; encoding= &quot;UTF-8&quot; ?> <application xmlns= &quot;; > <!-- The application identifier string, unique to this application. --> <id> </id> <!-- Used as the filename for the application --> <filename> flexGalaVideoBrowser </filename> [.....] <initialWindow> <content> index.html </content> <systemChrome> none </systemChrome> <transparent> true </transparent> <visible> false </visible> <!-- The window's initial size . --> <width> 360 </width> <height> 590 </height> <!-- The window's initial position --> <x> 50 </x> <y> 50 </y> </initialWindow> [.....] <application>
  101. Custom chrome windows functionalities We choosed to use our custom chrome so needs to be defined desired window functionalities: closing,minizing and resizing. function doMinimizeClick (){ nativeWindow . minimize (); } function doCloseClick (){ window . close (); } function onResize(){ nativeWindow . startResize ( air . NativeWindowResize . BOTTOM_RIGHT ); }
  102. Videoplayer HTML layout Video player HTML is defined in external document inserted in ours application layout via “Iframe” elements. In this way we can separates and better manages different elements. < iframe id = &quot;videoContainer&quot; src = &quot;video.html&quot; sandboxRoot = &quot;; documentRoot = &quot;app:/&quot;/>
  103. Video and Main Application relationships Defines mapping between main application functions and videoPlayer HTML presentation layout. [ Main Application ] // Map functions across security sandbox exposed . open = open ; exposed . pause = pause ; exposed . resume = resume ; // Add functions to IFRAME document document . getElementById ( 'videoContainer' ). contentWindow . parentSandboxBridge = exposed ; [ Video player ] // Called when the play button is clicked // Controls playback/pause and provides appropriate UI function doPlayClick ()‏ { parentSandboxBridge . pause (); document . getElementById ( 'play' ). src = PLAY_OVER ; }
  104. Manages Window Growing animation We want animates window when first video is requested to play. Spry Framework offers a simple way to do it. var enlargeAnimation = new Spry . Effect . Grow ( {TARGET_HTML_ELEMENTS} , { duration , from , to , growCenter , referHeight , toggle , transition , setup , finish } );
  105. Manages Window Growing animation We want sinchronize HTML element growing size with our's NATIVE WINDOW bounds, we do that in an ENTER_FRAME handler. // callback used to synchronize windows width to content width function doGrowing ( eventObj ) { window . nativeWindow . width = getVideoContainer (). clientWidth + getVideoContainer (). offsetLeft ; window . nativeWindow . height = getVideoContainer (). clientHeight + getVideoContainer (). offsetTop ; air . Introspector . Console . log ( &quot;new w: &quot; + window . nativeWindow . width ); air . Introspector . Console . log ( &quot;new h: &quot; + window . nativeWindow . height ); } function getVideoContainer () { return document . getElementById ( IFRAME_NAME ); }
  106. onClosing window event Before application close itself, via custom close button, we need to remove all handlers registered to ENTER_FRAME events. This is required to avoid possible runtime errors generated during close operation. window . nativeWindow . addEventListener ( air . Event . CLOSING , onClosingHandler ); function onClosingHandler ( e ){ // remove EnterFrame event before closing to avoid unexpected exceptions window . htmlLoader . stage . removeEventListener ( air . Event . ENTER_FRAME , doFrame ); }
  107. compiles with AptanaStudio Aptana offers integrated wizard to manage Adobe Air SDK compiling options. Offers also a standard application certificate to be used if you don't have your own.
  108. features enhancement This application is inteded as a first draft of more complex and usefull tools that will be offered to FLEXGALA registered users. Extra features will be added as: - load and play locals FLVs files - show/hide video panels - notifications when new video are availables - and more.... Stay tuned on newsletter for incoming updates.
  109. we make it RIA Marco Casario CTO – Comtaste