SlideShare a Scribd company logo
Flex with Rest and Optimazation MyLabs Flex with Rest and Optimazation
Ways between AJAX and Flex using the flashVars properties,  querying string parameters,  using the navigateToURL() method using the ExternalInterface class
Using FlashVar Property You pass request data to Flex applications by defining the flashVars properties in the wrapper The flashVars properties and URL fragments are read in the Flex application at run time. As a result, changing flashVars properties or URL fragments does not require you to recompile the Flex application.
Using FlashVar Property <html> <head> <title>/flex2/code/wrapper/SimplestFlashVarTestWrapper.html</title> <style> body { margin: 0px; overflow:hidden } </style> </head> <body scroll='no'> <table width='100%' height='100%' cellspacing='0' cellpadding='0'><tr><td valign='top'> <h1>Simplest FlashVarTest Wrapper</h1> <object id='mySwf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'    codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab' height='100%' width='100%'> <param name='src' value='FlashVarTest.swf'/> <param name='flashVars' value='firstName=Nick&lastName=Danger'/> <embed name='mySwf' src='FlashVarTest.swf' pluginspage='http://www.adobe.com/go/getflashplayer' height='100%'  width='100%' flashVars='firstName=Nick&lastName=Danger'/> </object> </td></tr></table> </body> </html>
Using URL fragments  Append value to the SWF file’s URL in the HTML wrapper that embeds the Flex application. http://www.domain.com/myApp.swf  firstName=Marco&lastname=Casario In your Flex app to access the values you use the  Application.application.parameters  object:
Using URL fragments  <mx:Script> <![CDATA[ import mx.managers.BrowserManager; import mx.managers.IBrowserManager; import mx.utils.URLUtil; private var bm:IBrowserManager; [Bindable] private var fName:String; [Bindable] private var lName:String;  private function init(e:Event):void { bm = BrowserManager.getInstance();  bm.init(&quot;&quot;, &quot;Welcome!&quot;); /* The following code will parse a URL that passes firstName and lastName as query string parameters after the &quot;#&quot; sign; for example: http://www.mydomain.com/MyApp.html#firstName=Nick&lastName=Danger */ var o:Object = URLUtil.stringToObject(bm.fragment, &quot;&&quot;);  fName = o.firstName; lName = o.lastName;  } ]]> </mx:Script>
Using the  navigateToURL () method The  navigateToURL () method loads a document from aspecific URL into a window or passes variables to another application at a defined URL <?xml version=&quot;1.0&quot;?> <mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;> <mx:Script><![CDATA[ import flash.net.*; public function executeSearch(event:MouseEvent):void { var u:URLRequest = new URLRequest(&quot;http://www.google.com/search?hl=en&q=&quot; + ta1.text); navigateToURL(u,&quot;_blank&quot;); } ]]></mx:Script> <mx:TextArea id=&quot;ta1&quot;/> <mx:Button label=&quot;Search&quot; click=&quot;executeSearch(event)&quot;/> </mx:Application>
Using the navigateToURL() method You can use the navigateToURL() method to invoke JavaScript functions: / /in Flex  var u:URLRequest = new URLRequest(&quot; javascript:catchClick ('&quot;+ eName + &quot;','&quot; + eType +&quot;')&quot;); navigateToURL(u,&quot;_self&quot;); //On the HTML page <SCRIPT LANGUAGE=&quot;JavaScript&quot;> function catchClick(name, type) { alert(name + &quot; triggered the &quot; + type + &quot; event.&quot;); } </SCRIPT>
Using the ExternalInterface API  The ExternalInterface is part of the  flash.external  package 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. Moreover you can call any JavaScript method on the wrapper, pass parameters, and get a return value. The  ExternalInterface  class is the External API, an application programming interface that enables straightforward communication between ActionScript and the Flash Player container; for example, an HTML page with JavaScript, or a desktop application with Flash Player embedded. Use of ExternalInterface is recommended for all JavaScript-ActionScript communication.
Using the ExternalInterface API  Access javascript from flex <![CDATA[ import mx.controls.Alert; private function init():void { var userAgent:String = ExternalInterface.call(&quot;navigator.userAgent.toString&quot;); Alert.show(userAgent, &quot;navigator.userAgent:&quot;); } ]]> </mx:Script> <mx:ApplicationControlBar dock=&quot;true&quot;> <mx:Button label=&quot;Display user agent&quot; click=&quot;init();&quot; /> </mx:ApplicationControlBar>
Using the ExternalInterface API  Access flex from javascript public function myFunc(s:String):void { // whatever you want} public function initApp():void { ExternalInterface.addCallback(&quot;myFlexFunction&quot;,myFunc); }  <SCRIPT LANGUAGE=&quot;JavaScript&quot;> function callApp() { window.document.title = document.getElementById(&quot;newTitle&quot;).value; mySwf.myFlexFunction(window.document.title); } </SCRIPT>
ExternalInterface API security Restrictions: 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.  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. <object id=ā€˜myName' classid=' clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'  codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab'  allowScriptAccess='always'   height='100%' width='100%'>
The Flex AJAX Bridge 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. It will save you a lot of time. Using the library anything you can do with ActionScript, you can do with JavaScript.
When to use the Flex AJAX Bridge The FABridge library is useful in the following situations: 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. 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.
Optimization Framework Optimization Code Optimization
Framework Optimization Runtime Shared Libraries (RSLs) Flex 1.5 introduced the concept of Runtime Shared Libraries (RSLs). With RSLs, you can reduce the size of your application’s SWF file by externalizing shared assets into standalone files that can be separately downloaded and cached on the client. These shared assets are loaded by any number of applications at runtime, but only need to be transferred to the client once. If you have multiple applications but those applications share a core set of graphic files, components, and other assets, your users only have to download those assets once in an RSL. You can reduce the resulting file size for your main application dramatically. If a file in one of the RSLs changes, Flex recompiles and resends that RSL to the client. Flex does not recompile the application and other unchanged RSLs.
Code Optimization Object creation Measurement/Layout  Rendering
Optimizing Actionscript: Object Creation Solution #1: Deferred Creation Delay object creation until the object becomes visible Is baked into Accordion, TabNavigator, and ViewStack Can be added to custom containers, but subclassing ViewStack is easier
Optimizing Actionscript: Object Creation Solution #2: Ordered Creation During startup, stagger creation of objects <mx:Application> <mx:Panel width=&quot;250&quot; height=&quot;100&quot;  creationPolicy=ā€œqueuedā€  /> <mx:Label text=&quot;One&quot; /> </mx:Panel> <mx:Panel width=&quot;250&quot; height=&quot;100&quot;  creationPolicy=ā€œqueuedā€  /> <mx:Label text=&quot;Two&quot; /> </mx:Panel> </mx:Application>
Measurement/Layout: Definition The process of assigning a position and size to every component <mx:Application>   <mx:HBox>   <mx:Button label=ā€œ1ā€/>   <mx:Button label=ā€œ2ā€/>   </mx:HBox>   <mx:TextArea width=ā€œ100%ā€ height=ā€œ100%ā€ text=ā€œTextā€/>  </mx:Application>
Solution #1: Reduce Container Nesting Try to use HBox and VBox instead of Grid Avoid nesting a VBox inside a Panel or Application The root of an MXML component doesn’t need to be a Container Use Canvas with constraints Warning sign: a Container with a single child
Useful Links http://livedocs.adobe.com/flex/3/

More Related Content

PPT
Flex in portal
Sunil Patil
Ā 
PPT
Csphtp1 20
HUST
Ā 
PDF
A World Beyond Ajax Accessing Googles Ap Is From Flash And Non Java Script En...
GoogleTecTalks
Ā 
PPT
Php
Mindtree
Ā 
PPT
.Net course-in-mumbai-ppt
vibrantuser
Ā 
PPT
Ibm
techbed
Ā 
PPTX
Ajax control tool kit
Vidhi Patel
Ā 
PPT
Developing an ASP.NET Web Application
Rishi Kothari
Ā 
Flex in portal
Sunil Patil
Ā 
Csphtp1 20
HUST
Ā 
A World Beyond Ajax Accessing Googles Ap Is From Flash And Non Java Script En...
GoogleTecTalks
Ā 
Php
Mindtree
Ā 
.Net course-in-mumbai-ppt
vibrantuser
Ā 
Ibm
techbed
Ā 
Ajax control tool kit
Vidhi Patel
Ā 
Developing an ASP.NET Web Application
Rishi Kothari
Ā 

What's hot (20)

PPTX
Ajax and ASP.NET AJAX
Julie Iskander
Ā 
PPTX
ASP.NET MVC Performance
rudib
Ā 
KEY
Introduction to ASP.NET MVC
LearnNowOnline
Ā 
PPT
Ta Javaserverside Eran Toch
Adil Jafri
Ā 
PPT
ASP.NET AJAX Basics
petrov
Ā 
PPT
ASP.NET 05 - Exception Handling And Validation Controls
Randy Connolly
Ā 
PPT
Silverlight 2 for Developers - TechEd New Zealand 2008
Jonas FollesĆø
Ā 
PDF
Angular - Chapter 3 - Components
WebStackAcademy
Ā 
PPT
Introduction To Asp.Net Ajax
Jeff Blankenburg
Ā 
PPT
Your First ASP_Net project part 1
Biswadip Goswami
Ā 
PPT
Ajax & ASP.NET 2
Talal Alsubaie
Ā 
PPTX
Ajax control asp.net
Sireesh K
Ā 
PPT
ASP.NET 03 - Working With Web Server Controls
Randy Connolly
Ā 
PDF
Flutter State Management Using GetX.pdf
Katy Slemon
Ā 
PPSX
Asp.net mvc
Er. Kamal Bhusal
Ā 
PPT
Entity frameworks101
Rich Helton
Ā 
PPTX
A View about ASP .NET and their objectives
Department of Computer Science, Bharathidasan University, Tiruchirappalli
Ā 
PDF
Adding User Management to Node.js
Dev_Events
Ā 
PPTX
MVC Training Part 2
Lee Englestone
Ā 
PPT
Intro To Asp Net And Web Forms
SAMIR BHOGAYTA
Ā 
Ajax and ASP.NET AJAX
Julie Iskander
Ā 
ASP.NET MVC Performance
rudib
Ā 
Introduction to ASP.NET MVC
LearnNowOnline
Ā 
Ta Javaserverside Eran Toch
Adil Jafri
Ā 
ASP.NET AJAX Basics
petrov
Ā 
ASP.NET 05 - Exception Handling And Validation Controls
Randy Connolly
Ā 
Silverlight 2 for Developers - TechEd New Zealand 2008
Jonas FollesĆø
Ā 
Angular - Chapter 3 - Components
WebStackAcademy
Ā 
Introduction To Asp.Net Ajax
Jeff Blankenburg
Ā 
Your First ASP_Net project part 1
Biswadip Goswami
Ā 
Ajax & ASP.NET 2
Talal Alsubaie
Ā 
Ajax control asp.net
Sireesh K
Ā 
ASP.NET 03 - Working With Web Server Controls
Randy Connolly
Ā 
Flutter State Management Using GetX.pdf
Katy Slemon
Ā 
Asp.net mvc
Er. Kamal Bhusal
Ā 
Entity frameworks101
Rich Helton
Ā 
Adding User Management to Node.js
Dev_Events
Ā 
MVC Training Part 2
Lee Englestone
Ā 
Intro To Asp Net And Web Forms
SAMIR BHOGAYTA
Ā 
Ad

Viewers also liked (8)

PDF
Will bc day3
cobaltazure
Ā 
PPTX
An Apocalypse of Ice; chapter 7
cobaltazure
Ā 
PDF
Aao ichapter11
cobaltazure
Ā 
PDF
Apocalypse of Ice Chapter 12 Part 1
cobaltazure
Ā 
PDF
Clean code
Khou Suylong
Ā 
PPT
Share Vision First Trip
Khou Suylong
Ā 
PDF
TDD sharevison team
Khou Suylong
Ā 
PPTX
An Apocalypse of Ice; chapter 3
cobaltazure
Ā 
Will bc day3
cobaltazure
Ā 
An Apocalypse of Ice; chapter 7
cobaltazure
Ā 
Aao ichapter11
cobaltazure
Ā 
Apocalypse of Ice Chapter 12 Part 1
cobaltazure
Ā 
Clean code
Khou Suylong
Ā 
Share Vision First Trip
Khou Suylong
Ā 
TDD sharevison team
Khou Suylong
Ā 
An Apocalypse of Ice; chapter 3
cobaltazure
Ā 
Ad

Similar to Flex_rest_optimization (20)

PPT
Better Adobe Flex and AIR applications with AJAX
guestdb10f0
Ā 
PPT
Flex In Portal Final
Sunil Patil
Ā 
ODP
Switch To Flex
Joshua Partogi
Ā 
PPT
Introduction To Flex
Yoss Cohen
Ā 
PPT
Adobe Flex Introduction
Amal Biswas
Ā 
PPT
Flex 3 - Introduction
rakhtar
Ā 
PDF
Data exchange between flex and java script, 2007
Evgenios Skitsanos
Ā 
PPT
Test
guest25229c
Ā 
KEY
Best Practices for Webcam Augmented Reality
Zugara
Ā 
PPT
Flex For Flash Developers Ff 2006 Final
ematrix
Ā 
PPT
Flex And Ria
ravinxg
Ā 
PPT
Flex RIA
rssharma
Ā 
ODP
Developing for Mobile with the Flex Framework
Matthew Fabb
Ā 
PPT
Adobe Flex4
Rich Helton
Ā 
PDF
Flex Introduction
Sabarinathan Masilamani
Ā 
PPT
Optimizing Flex Applications
dcoletta
Ā 
PPTX
Exploring Adobe Flex
senthil0809
Ā 
PPS
Afik Gal @alphageeks: Flex Intro
Alphageeks
Ā 
PPT
Enterprise AIR Development for JavaScript Developers
AndreCharland
Ā 
PDF
Ria
everfountain
Ā 
Better Adobe Flex and AIR applications with AJAX
guestdb10f0
Ā 
Flex In Portal Final
Sunil Patil
Ā 
Switch To Flex
Joshua Partogi
Ā 
Introduction To Flex
Yoss Cohen
Ā 
Adobe Flex Introduction
Amal Biswas
Ā 
Flex 3 - Introduction
rakhtar
Ā 
Data exchange between flex and java script, 2007
Evgenios Skitsanos
Ā 
Test
guest25229c
Ā 
Best Practices for Webcam Augmented Reality
Zugara
Ā 
Flex For Flash Developers Ff 2006 Final
ematrix
Ā 
Flex And Ria
ravinxg
Ā 
Flex RIA
rssharma
Ā 
Developing for Mobile with the Flex Framework
Matthew Fabb
Ā 
Adobe Flex4
Rich Helton
Ā 
Flex Introduction
Sabarinathan Masilamani
Ā 
Optimizing Flex Applications
dcoletta
Ā 
Exploring Adobe Flex
senthil0809
Ā 
Afik Gal @alphageeks: Flex Intro
Alphageeks
Ā 
Enterprise AIR Development for JavaScript Developers
AndreCharland
Ā 

Recently uploaded (20)

PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
Ā 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
Ā 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
Ā 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
Ā 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
Ā 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
Ā 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
Ā 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
Ā 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
Ā 
PDF
OFFOFFBOXā„¢ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
Ā 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
Ā 
PDF
Software Development Methodologies in 2025
KodekX
Ā 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
Ā 
PDF
The Future of Artificial Intelligence (AI)
Mukul
Ā 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
Ā 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
Ā 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
Ā 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
Ā 
cloud computing vai.pptx for the project
vaibhavdobariyal79
Ā 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
Ā 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
Ā 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
Ā 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
Ā 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
Ā 
Presentation about Hardware and Software in Computer
snehamodhawadiya
Ā 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
Ā 
OFFOFFBOXā„¢ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
Ā 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
Ā 
Software Development Methodologies in 2025
KodekX
Ā 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
Ā 
The Future of Artificial Intelligence (AI)
Mukul
Ā 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
Ā 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
Ā 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
Ā 

Flex_rest_optimization

  • 1. Flex with Rest and Optimazation MyLabs Flex with Rest and Optimazation
  • 2. Ways between AJAX and Flex using the flashVars properties, querying string parameters, using the navigateToURL() method using the ExternalInterface class
  • 3. Using FlashVar Property You pass request data to Flex applications by defining the flashVars properties in the wrapper The flashVars properties and URL fragments are read in the Flex application at run time. As a result, changing flashVars properties or URL fragments does not require you to recompile the Flex application.
  • 4. Using FlashVar Property <html> <head> <title>/flex2/code/wrapper/SimplestFlashVarTestWrapper.html</title> <style> body { margin: 0px; overflow:hidden } </style> </head> <body scroll='no'> <table width='100%' height='100%' cellspacing='0' cellpadding='0'><tr><td valign='top'> <h1>Simplest FlashVarTest Wrapper</h1> <object id='mySwf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab' height='100%' width='100%'> <param name='src' value='FlashVarTest.swf'/> <param name='flashVars' value='firstName=Nick&lastName=Danger'/> <embed name='mySwf' src='FlashVarTest.swf' pluginspage='http://www.adobe.com/go/getflashplayer' height='100%' width='100%' flashVars='firstName=Nick&lastName=Danger'/> </object> </td></tr></table> </body> </html>
  • 5. Using URL fragments Append value to the SWF file’s URL in the HTML wrapper that embeds the Flex application. http://www.domain.com/myApp.swf firstName=Marco&lastname=Casario In your Flex app to access the values you use the Application.application.parameters object:
  • 6. Using URL fragments <mx:Script> <![CDATA[ import mx.managers.BrowserManager; import mx.managers.IBrowserManager; import mx.utils.URLUtil; private var bm:IBrowserManager; [Bindable] private var fName:String; [Bindable] private var lName:String; private function init(e:Event):void { bm = BrowserManager.getInstance(); bm.init(&quot;&quot;, &quot;Welcome!&quot;); /* The following code will parse a URL that passes firstName and lastName as query string parameters after the &quot;#&quot; sign; for example: http://www.mydomain.com/MyApp.html#firstName=Nick&lastName=Danger */ var o:Object = URLUtil.stringToObject(bm.fragment, &quot;&&quot;); fName = o.firstName; lName = o.lastName; } ]]> </mx:Script>
  • 7. Using the navigateToURL () method The navigateToURL () method loads a document from aspecific URL into a window or passes variables to another application at a defined URL <?xml version=&quot;1.0&quot;?> <mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;> <mx:Script><![CDATA[ import flash.net.*; public function executeSearch(event:MouseEvent):void { var u:URLRequest = new URLRequest(&quot;http://www.google.com/search?hl=en&q=&quot; + ta1.text); navigateToURL(u,&quot;_blank&quot;); } ]]></mx:Script> <mx:TextArea id=&quot;ta1&quot;/> <mx:Button label=&quot;Search&quot; click=&quot;executeSearch(event)&quot;/> </mx:Application>
  • 8. Using the navigateToURL() method You can use the navigateToURL() method to invoke JavaScript functions: / /in Flex var u:URLRequest = new URLRequest(&quot; javascript:catchClick ('&quot;+ eName + &quot;','&quot; + eType +&quot;')&quot;); navigateToURL(u,&quot;_self&quot;); //On the HTML page <SCRIPT LANGUAGE=&quot;JavaScript&quot;> function catchClick(name, type) { alert(name + &quot; triggered the &quot; + type + &quot; event.&quot;); } </SCRIPT>
  • 9. Using the ExternalInterface API The ExternalInterface is part of the flash.external package 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. Moreover you can call any JavaScript method on the wrapper, pass parameters, and get a return value. The ExternalInterface class is the External API, an application programming interface that enables straightforward communication between ActionScript and the Flash Player container; for example, an HTML page with JavaScript, or a desktop application with Flash Player embedded. Use of ExternalInterface is recommended for all JavaScript-ActionScript communication.
  • 10. Using the ExternalInterface API Access javascript from flex <![CDATA[ import mx.controls.Alert; private function init():void { var userAgent:String = ExternalInterface.call(&quot;navigator.userAgent.toString&quot;); Alert.show(userAgent, &quot;navigator.userAgent:&quot;); } ]]> </mx:Script> <mx:ApplicationControlBar dock=&quot;true&quot;> <mx:Button label=&quot;Display user agent&quot; click=&quot;init();&quot; /> </mx:ApplicationControlBar>
  • 11. Using the ExternalInterface API Access flex from javascript public function myFunc(s:String):void { // whatever you want} public function initApp():void { ExternalInterface.addCallback(&quot;myFlexFunction&quot;,myFunc); } <SCRIPT LANGUAGE=&quot;JavaScript&quot;> function callApp() { window.document.title = document.getElementById(&quot;newTitle&quot;).value; mySwf.myFlexFunction(window.document.title); } </SCRIPT>
  • 12. ExternalInterface API security Restrictions: 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. 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. <object id=ā€˜myName' classid=' clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab' allowScriptAccess='always' height='100%' width='100%'>
  • 13. The Flex AJAX Bridge 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. It will save you a lot of time. Using the library anything you can do with ActionScript, you can do with JavaScript.
  • 14. When to use the Flex AJAX Bridge The FABridge library is useful in the following situations: 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. 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.
  • 16. Framework Optimization Runtime Shared Libraries (RSLs) Flex 1.5 introduced the concept of Runtime Shared Libraries (RSLs). With RSLs, you can reduce the size of your application’s SWF file by externalizing shared assets into standalone files that can be separately downloaded and cached on the client. These shared assets are loaded by any number of applications at runtime, but only need to be transferred to the client once. If you have multiple applications but those applications share a core set of graphic files, components, and other assets, your users only have to download those assets once in an RSL. You can reduce the resulting file size for your main application dramatically. If a file in one of the RSLs changes, Flex recompiles and resends that RSL to the client. Flex does not recompile the application and other unchanged RSLs.
  • 17. Code Optimization Object creation Measurement/Layout Rendering
  • 18. Optimizing Actionscript: Object Creation Solution #1: Deferred Creation Delay object creation until the object becomes visible Is baked into Accordion, TabNavigator, and ViewStack Can be added to custom containers, but subclassing ViewStack is easier
  • 19. Optimizing Actionscript: Object Creation Solution #2: Ordered Creation During startup, stagger creation of objects <mx:Application> <mx:Panel width=&quot;250&quot; height=&quot;100&quot; creationPolicy=ā€œqueuedā€ /> <mx:Label text=&quot;One&quot; /> </mx:Panel> <mx:Panel width=&quot;250&quot; height=&quot;100&quot; creationPolicy=ā€œqueuedā€ /> <mx:Label text=&quot;Two&quot; /> </mx:Panel> </mx:Application>
  • 20. Measurement/Layout: Definition The process of assigning a position and size to every component <mx:Application> <mx:HBox> <mx:Button label=ā€œ1ā€/> <mx:Button label=ā€œ2ā€/> </mx:HBox> <mx:TextArea width=ā€œ100%ā€ height=ā€œ100%ā€ text=ā€œTextā€/> </mx:Application>
  • 21. Solution #1: Reduce Container Nesting Try to use HBox and VBox instead of Grid Avoid nesting a VBox inside a Panel or Application The root of an MXML component doesn’t need to be a Container Use Canvas with constraints Warning sign: a Container with a single child