Adobe Flex4


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Adobe Flex4

  1. 1. AppSec (By Rich Helton) Flex 4 (Rev 1) State of Colorado Office of Cyber Security
  2. 2. The Case for RIA <ul><li>Since RIA keeps most of the work on the browser and less on the backend. Very strong graphics are a good case for RIA. </li></ul><ul><li>For example a Map Viewer, that doesn’t have to go back to the database very often, but does require a lot of interaction with an image that is already loaded in the browser. </li></ul><ul><li>RIA acts on a plugin, as long as the plugin is installed, the code is browser agnostic. </li></ul>
  3. 3. Adobe Flex <ul><li>Adobe Flex is a Software Development Kit from Adobe to create Rich Internet Applications (RIA) that plug into the Web Browser’s Flash plugin. </li></ul><ul><li>Flex uses MXML, the Macromedia XML, as a declarative layout of the interfaces to compile into the SWF file that is deployed. </li></ul><ul><li>To extend the MXML, Flex uses a language called ActionScript, which is similar to JavaScript. ActionScript can be called from the MXML file using the <mx:script> tag. </li></ul><ul><ul><li><mx:script source = “”/> </li></ul></ul>
  4. 4. Adobe AIR <ul><li>The purpose of Adobe Flex is to provide a framework to interact with the Adobe AIR plugin for GUI implementation of a product. </li></ul><ul><li>There are other SDK’s that could be used instead instead of ADOBE FLEX, for instance the GWT 4 AIR SDK, found at , that may provide more Java like components. </li></ul>
  5. 5. MXML Hello World Example <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> </li></ul><ul><li><mx:Application xmlns:mx=&quot;; layout=&quot;absolute&quot; backgroundGradientColors=&quot;[#000011, #333333]&quot;> <mx:Label text=&quot;Hello World!&quot; verticalCenter=&quot;0&quot; horizontalCenter=&quot;0&quot; fontSize=&quot;48&quot; letterSpacing=&quot;1&quot;> <mx:filters> </li></ul><ul><li><mx:GlowFilter color=&quot;#ffffdd&quot;/> </mx:filters> </mx:Label> </li></ul><ul><li></mx:Application> </li></ul>
  6. 6. FlexBuilder 3 Example
  7. 7. Example <mx:CreditCardValidator> tag
  8. 8. Sample 1
  9. 9. MXML Example <ul><li>In this example, it will display a control button called “Click on Me” that once clicked will display an Alert called “Event Handler”: </li></ul>
  10. 10. BlazeDS
  11. 11. BlazeDS <ul><li>With RIA, many of the pieces will run on the Browser environment, for this reason, a transport is need to the Server environment. </li></ul><ul><li>BlazeDS is an interface for Java Web and Java Remoting. </li></ul><ul><li>It can be found at </li></ul><ul><li>With BlazeDS, the backend to Flex could be a Web Service, Java Spring or even Java Hibernate. </li></ul><ul><li>The BlazeDS backend could be a multitude of Application Servers, including Tomcat, Jboss, WebLogic, and WebSphere. </li></ul><ul><li>BlazeDS is Open Source and can be freely used. </li></ul><ul><li>A Feature set can be found at </li></ul>
  12. 12. BlazeDS Services <ul><li>BlazeDS has a Remoting, Proxying and Messaging Service. </li></ul><ul><li>Remoting allows a connection to Server Side Java through a binary Action Message Format (AMF). AMF uses the “RemoteObject” class for remoting which is fasted than WebServices. </li></ul><ul><li>The HTTP Proxying Service will provide a cross domain proxy when direct communication is restricted through HTTP. </li></ul><ul><li>The Messaging Service can broadcasts messages to other clients. </li></ul><ul><li>The crossdomain.xml is required to be used for Service invocations to other sub-domains. </li></ul><ul><li>The “send()” method call will invoke a HTTP Service request. </li></ul>
  13. 13. BlazeDS Installation <ul><li>BlazeDS download has a turnkey download that comes preloaded with Tomcat 6. This requires that JDK 1.5 is installed. </li></ul><ul><li>After the turnkey installation, just run the samples as “catalina.bat run” from the /tomcat/bin directory. </li></ul><ul><li>The samples can be accessed from the http://localhost:8400/samples/ : </li></ul>
  14. 14. BlazeDS Installation <ul><li>BlazeDS sample message broker at http://localhost:8400/samples/traderdesktop/index.html : </li></ul>
  15. 15. BlazeDS Installation <ul><li>BlazeDS ds-console http://localhost:8400/ds-console/ : </li></ul>
  16. 16. Config files <ul><li>Several Config files can be found ~tomcatwebappsblazedsWEB-INFflex: </li></ul>
  17. 17. Config files <ul><li>messaging-config.xml - The messaging-config.xml file contains configuration settings for the Messaging Service. </li></ul><ul><li>services-config.xml - The services-config.xml file is the top-level configuration file for BlazeDS. Generally, you reference configuration files for specific services, such as messaging, in this file. You also define system-wide settings such as messaging channels and security contraints in this file. </li></ul><ul><li>remoting-config.xml - The BlazeDS RemotingService has traditionally been configured by the inclusion of a remoting-config.xml file in the BlazeDS XML configuration. </li></ul><ul><li>proxy-config.xml - The Proxy Service configuration file, which defines Proxy Service destinations for working with web services and HTTP services (REST services). </li></ul><ul><li>See </li></ul>
  18. 18. WAR files <ul><li>There are several Web Archive (WAR) files that make up BlazeDS. </li></ul><ul><li>blazeds.war – This is the starting copy of BlazeDS. </li></ul><ul><li>ds-console.war - Contains the management console application that provides runtime information about BlazeDS. </li></ul><ul><li>sample.war – Contains sample BlazeDS applications, configurations and documentation. </li></ul>
  19. 19. AMF <ul><li>There are many Open Source versions of the AMF protocol, that may not even be from Adobe, one reference for the Java Flash Remoting is for the OpenAMF project that is a free open-source alternative to Macromedia's Java Flash Remoting. </li></ul><ul><li>The specification for AMF version 3 can be found at </li></ul>
  20. 20. Sandbox Bridge <ul><li>You can use a sandbox bridge when content in the application sandbox must access properties or methods defined by content in a non-application sandbox, or when non-application content must access properties and methods defined by content in the application sandbox. Create a bridge with the childSandboxBridge and parentSandboxBridge properties of the window object of any child document. </li></ul><ul><li>This will allow you to expose methods that are defined in your AIR application to your SWF and load remote SWF with HTTP. </li></ul>
  21. 21. RemoteClass <ul><li>The Data Transfer Object uses the [RemoteClass] metadata tag. </li></ul><ul><li>This is part of Flex Remoting. </li></ul><ul><li>This is part of AMF Binding from Java to ActionScript through BlazeDS. </li></ul><ul><li>Example ActionScript: </li></ul><ul><li>Example Java: </li></ul>
  22. 22. LifeCycle Data Services (LCDS)
  23. 23. AMF and RTMP <ul><li>BlazeDS includes Adobe’s Action Message Format (AMF). Both are open source, and AMF is a binary remote format that is fast. </li></ul><ul><li>Life Cycle Data Services (LCDS) is not open source and has a license cost. LCDS includes the Real Time Messaging Protocol (RTMP) which uses J2EE and the Java Transaction API. </li></ul><ul><li>LCDS ES is an Enterprise Server for J2EE support. </li></ul><ul><li>LCDS uses RTMP T (Tunneling) for HTTP tunneling to traverse firewalls. </li></ul><ul><li>LCDS uses RTMP S (SSL Protocol) to encrypt the connection. See </li></ul>
  24. 24. LCDS <ul><li>Information for LCDS can be found at </li></ul><ul><li>Allows you to receive data just as you need it for data paging. </li></ul><ul><li>Is not open source and requires a license fee. </li></ul><ul><li>Some of the features include a SQL and Hibernate Adaptor as well as RTMP. </li></ul><ul><li>Note: Both LCDS and BlazeDS support JMS. </li></ul>
  25. 25. MXML Component Architecture
  26. 26. MXML Pieces <ul><li>Events – Events determine the flow of the application. For example, a user clicking on the Mouse Button. There are user and system events. </li></ul><ul><li>Controls -- Controls are user-interface components such as Button, TextArea, and ComboBox controls. Adobe Flex has two types of controls: basic and data provider. </li></ul><ul><li>Layouts -- In Adobe Flex, layout containers provide a hierarchical structure to arrange and configure the components, such as Button and ComboBox controls, of a Flex application. </li></ul><ul><li>Navigators – Navigators are a hybrid component designed to handle content visibility. They work much like a layout container and a control mixed together. </li></ul><ul><li>Nonvisual Components – Flex also provides nonvisual components that handle functionality, such as an Array or XMLList. </li></ul>
  27. 27. An Event <ul><li>A very typical even is a button click on a form. This can be done with with a Mouse click. </li></ul><ul><li>All Buttons dispatch a MouseEvent of type click, it defined in code as MouseEvent.CLICK. </li></ul><ul><li>To extend the Event class, you need to invoke the superclass constructor within your custom constructor. </li></ul><ul><li>The Event class properties hold the basic information about an event. </li></ul><ul><li>The Event class methods can be used in event listener functions for affecting the behavior of the Event object. </li></ul><ul><li>The currentTarget, eventPhase, and bubbles are properties of the Event class. </li></ul>
  28. 28. MXML Pieces <ul><li>Functions – Named functions should be placed within a Script/CDATA block, and they can be called from inline script as well as other functions. Named functions can receive parameters and/or return typed values. </li></ul><ul><li>Variables -- Variables allow you to store values that you use in your program. To declare a variable, you must use the var statement with the variable name. </li></ul><ul><li>Data Types – The primitive data types include Boolean, int, Null, Number, String, uint, and void. The ActionScript core classes also define the following complex data types: Object, Array, Date, Error, Function, RegExp, XML, and XMLList. </li></ul>
  29. 29. MXML Pieces <ul><li>Classes – A class is like a blueprint for an object. Classes define the properties and methods an object will have. </li></ul><ul><li>Object -- The Object class is at the root of the ActionScript class hierarchy. Objects are created by constructors using the new operator syntax, and can have properties assigned to them dynamically. Objects can also be created by assigning an object literal, as in:var obj:Object = {a:&quot;foo&quot;, b:&quot;bar&quot;} </li></ul><ul><li>Comments -- An ASDoc comment consists of the text between the characters /** that mark the beginning of the ASDoc comment, and the characters */ that mark the end of it. The text in a comment can continue onto multiple lines. MXML uses <!-- and -->. </li></ul>
  30. 30. ActionScript
  31. 31. ActionScript <ul><li>The Adobe reference to ActionScript </li></ul><ul><li>To extend the MXML, Flex uses a language called ActionScript, which is similar to JavaScript. </li></ul><ul><li>ActionScript can be added inline into the MXML code. </li></ul>
  32. 32. UIComponent <ul><li>The UIComponent class is the base class for all Flex visual components. For example, the Button inherits its “click” event from the UIComponent. </li></ul><ul><li>In order to control the layout of the UIComponent within Spark containers, the BasicLayout container is required. </li></ul><ul><li>The validateNow() method of the UIComponent class is used to validate and update the layout of a custom component and redraw it on screen. </li></ul><ul><li>The UIComponent is a preloader of a Flex application. </li></ul><ul><li>When creating a custom component, for example MyComp, based on a UIComponent class, it is best to declare the class using: </li></ul><ul><ul><li>public class MyComp extends UIComponent { } </li></ul></ul>
  33. 33. UIComponent <ul><li>The commitProperties, updateDisplayList, and createChildren are the protected methods of the UIComponent class. </li></ul>
  34. 34. Sample program <ul><li>Here’s a simple program to print out the Mouse Coordinates as they move: </li></ul>
  35. 35. Sample program <ul><li>Mouse Move is the inline ActionScript: </li></ul>
  36. 36. Another Sample <ul><li>Here is example that moves a circle with a mouse: </li></ul>
  37. 37. Another Sample <ul><li>This sample uses an event Listener to listen for the events that are defined by constants: </li></ul>
  38. 38. addEventListener <ul><li>The ItemResponder class handles and dispatches event objects to ActionScript event handler functions and can be used instead of attribute-based event listeners or the addEventListerner() method. </li></ul>
  39. 39. Data Binding <ul><li>See </li></ul><ul><li>Data Binding is the process of tying the data in one object into another object. </li></ul><ul><li>It provides a convenient way to pass data between the different layers of the application. </li></ul><ul><li>Data binding requires a source property, a destination property, and a triggering event that indicates when to copy the data from the source to the destination. </li></ul><ul><li>You can define a data binding in ActionScript by using the mx.binding.utils.BindingUtils class. </li></ul>
  40. 40. Binding Watcher <ul><li>See </li></ul><ul><li>Flex includes the mx.binding.utils.ChangeWatcher class to define a data-binding watcher. </li></ul><ul><li>Typically, a data-binding watcher invokes an event listener when a binding occurs. </li></ul><ul><li>To set up a data-binding watcher, use the static watch ( ) method of the ChangeWatcher class. </li></ul>
  41. 41. Spark Component Architecture
  42. 42. Layouts <ul><li>Spark is a new component in Flex 4 for skinning and Layouts. See and </li></ul><ul><li>Spark layouts use layout classes, while MX layouts do not use layout classes. </li></ul>
  43. 43. Skinnable Container <ul><li>The skinClass is a MXML attribute that specifies the visual implementation of a Spark component. It is used to apply skins to the Skinnable Container. </li></ul><ul><li>the SkinnableComponent is the superclass of all Spark components. </li></ul><ul><li>If making a custom component that extends the Skinnable Container, you should define the SkinPart metadata to make the component required to ensure that the skin of your component uses the layout. </li></ul><ul><li>A SparkSkin class for Button Component is defined such as : </li></ul><ul><ul><li><s:Button styleName=“ButtonSkin”/> </li></ul></ul>
  44. 44. ItemRenderers <ul><li>Three ItemRenderers in Flex are Inline, Component and Drop-In. </li></ul><ul><li>You can create a custom ItemRenderer to display data that does affect the underlying data. </li></ul><ul><li>The showCaret, label, and data properties of the ItemRenderer class are used by the host component to pass information to the renderer. </li></ul><ul><li>The normalAndShowCaret, hovered and normal are the view states defined for the item renderers. </li></ul>
  45. 45. Layout Containers
  46. 46. ViewStack <ul><li>The ViewStack is a navigator container that is made up of a collection of child containers. </li></ul><ul><li>Only one container is visible at a time. </li></ul><ul><li>The “selectedChild” component will indicate the position of the current selected child to display. </li></ul><ul><li>The layout property of the Groupcomponent will define the children’s orientation. </li></ul><ul><li>Implement the IVisualElement interface to ensure a Spark Group can take the components as child objects. </li></ul><ul><li>If the ViewStack has multiple children, and the children need to be loaded before the application is available for use, then the creationPolicy and each NavigatorContent on the children has to be set. </li></ul><ul><li>The TabNavigator is the container child class of ViewStack having a collection of child containers in which only one can be visible at a time. </li></ul>
  47. 47. LayoutBase <ul><li>LayoutBase is a superclass used to create custom layouts. </li></ul><ul><li>One use is to display a number of images in a carousel. </li></ul><ul><li>See for Layout containers. </li></ul>
  48. 48. DataGrid Control <ul><li>The features of the DataGrid control include customizable column headers, resizing the columns at runtime, and re-ordering of the columns at runtime. See </li></ul><ul><li>The createItemEditor method of the DataGrid class is used to create the item editor for the item renderer at the editedItemPosition. </li></ul>
  49. 49. ViewState <ul><li>The currentState property is used to get the name of the view state that a user wants to display while the click event occurs. </li></ul><ul><li>See </li></ul>
  50. 50. Collections <ul><li>Collections are objects that provide a uniform way to access and represent the data/items contained in a source object, such as an Array or and XMLList. </li></ul><ul><li>Collections can provide a level of abstaraction between Flex components and the source objects that populate them. </li></ul><ul><li>They provide a mechanism to handle paged data from remote data sources. </li></ul><ul><li>They use collection methods to access data in the primary data source. </li></ul><ul><li>It can provide a specific view of the data to be sorted or filtered by a developer-supplied method. </li></ul>
  51. 51. ArrayCollection <ul><li>The filterFunction property of an ArrayCollection returns a Boolean data type. </li></ul><ul><li>One of the characteristics related to the ArrayColleciton class is that the elements of the ArrayCollection class are monitored and used in bindings. </li></ul>
  52. 52. ICollectionView <ul><li>The refresh() method of the ICollectionView class can be used to update any control or container bound to data. </li></ul><ul><li>The filterFunction property is used by the ICollectionView class to remove items that do not match the function’s criteria. </li></ul>
  53. 53. URLLoader class <ul><li>The URLLoader has the following public functions: addEventListener, URLLoader, and close. </li></ul><ul><li>URLLoader, and URLStream, classes are used for loading XML or text files. </li></ul>
  54. 54. URLRequest class <ul><li>The URLRequest class has the following properties: cacheResponse, followRedirects, and manageCookies. </li></ul>
  55. 55. Files <ul><li>The FileMode.UPDATE mode specifies that the file will be opened for read and write operations. </li></ul><ul><li>The creationDate, creator, and downloaded properties of the File class are used to provide information about a file or directory. </li></ul>
  56. 56. FXG (Flash XML Graphics)
  57. 57. FXG <ul><li>FXG is a XML based language used to describe vector graphics elements and bitmap graphics </li></ul><ul><li>FXG can be embedded in MXML </li></ul><ul><li>FXG can be treated as ActionScript classes </li></ul><ul><li>Flex is Adobe, and Adobe has several graphics applications, FXG files can be exported, and imported, from Adobe Photoshop, Illustrator and Fireworks. </li></ul><ul><li>FXG blend modes include overlay, darken and invert. </li></ul><ul><li>See and </li></ul>
  58. 58. SVG Explorer <ul><li> </li></ul>
  59. 59. Flex Validation
  60. 60. Flex Validation <ul><li>There are many standard validators that come standard with the Flex framework. Some of the standard Flex 3 Validators can be found at </li></ul><ul><li>Flex can use a Regular Expression Validator to build upon the validation rules. </li></ul><ul><li>Some of the standard validators include Date, Email, Phone numbers, String, Number, Currency, ZipCode and SSNs. </li></ul><ul><li>In Flex validation, the “source” class specifies the property of the object to be validated. </li></ul><ul><li>Validators are subclasses of mx.validators.Validator and return True for a valid input format. </li></ul>
  61. 61. Flex Validation <ul><li>The removeListenerHandler method, of the Validator class, is used to disconnect all of the listeners for the valid and invalid events dispatched from the validator. </li></ul><ul><li>The matchedString property of the RegExpValidationResult class is used to contain the substring of the input String that matches the regular expression. </li></ul><ul><li>To invoke the validator programmatically, the Validator.validate() method is called. </li></ul>
  62. 62. Flex Formatter <ul><li>The Formatter will format the output of the data. </li></ul><ul><li>All formatters are subclasses of mx.formatters.Formatter. </li></ul><ul><li>The subclasses of Formatter that come with Flex 4 are CurrencyFormatter, DateFormatter, NumberFormatter, PhoneFormatter, and ZipCodeFormatter. </li></ul><ul><li>The Formatter class defines a format() method, which must be overridden by its subclasses. </li></ul><ul><li>The defaultInvalidFormatterError property of the Formatter class generates an error message for a worthless format string that is specified to the formatter. </li></ul>
  63. 63. FlexUnit
  64. 64. FlexUnit <ul><li>I have taught many classes on NUnit and JUnit. FlexUnit is the Flex equivalent for Unit testing Flex applications. </li></ul><ul><li>Some websites to visit for the open source software and </li></ul>