Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Discover The Unknown Flex 4.5 (MAX 2011)

Slides from "Discover The Unknown Flex 4.5" session presented at MAX 2011 by Piotr Walczyszyn.

  • Login to see the comments

Discover The Unknown Flex 4.5 (MAX 2011)

  1. 1. Discover the Unknown Flex 4.5 Piotr Walczyszyn | Adobe Enterprise Evangelist Blog: riaspace.com Twitter: @pwalczyszyn©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  2. 2. ls -al AS3 secrets Flex secrets Flash Builder secrets 2©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  3. 3. ** ******** **** **** **////// */// * **//** /** / /* ** //** /********* *** **********////////** /// * /**//////** /** * /* /** /** ******** / **** // // //////// //// 3©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  4. 4. AS3: Short conditional statements var someVar:Number; if (someVar)      doSomething(); 4©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  5. 5. AS3: Short constructors var point:Point = new Point; 5©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  6. 6. AS3: Throwing objects try { throw 1; }  catch (n:Number) { trace(n); // outputs 1 } 6©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  7. 7. AS3: arguments class dispatcher.addEventListener( SomeEvent.TYPE, function(event:SomeEvent):void { EventDispatcher(event.target). removeEventListener( event.type, arguments.callee ); }); 7©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  8. 8. AS3: ||= logical or assignment (by Sönke Rohde) var num:Number; num ||= 10; trace(num); // outputs 10 num = 5; trace(num); // outputs 5 num ||= 10; trace(num); // outputs 5 8©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  9. 9. AS3: Getting object class type var clazz:Class = Object(obj).constructor; 9©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  10. 10. AS3: Labels & continue (by Christian Cantrell) outerLoop: for (var i:uint = 0; i < outerArray.length; ++i) { var foo:String = outerArray[i]; innerLoop: for (var j:uint = 0; j < innerArray.length; ++j) { var bar:String = innerArray[j]; if (foo == bar) { continue outerLoop; } } trace(foo); } 10©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  11. 11. AS3: Label & break (by Christian Cantrell) dateCheck: { trace("Good morning."); var today:Date = new Date(); if (today.month == 11 && today.date == 24) // Christmas! { break dateCheck; } trace("Time for work!"); } 11©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  12. 12. AS3: with statement function polar(r:Number):void { var a:Number, x:Number, y:Number; with (Math) { a = PI * pow(r, 2); x = r * cos(PI); y = r * sin(PI / 2); } trace("area = " + a); trace("x = " + x); trace("y = " + y); } polar(3); 12©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  13. 13. AS3: global functions // globalFunction.as file package { public function globalFunction(text:String):void { trace(text); } } 13©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  14. 14. AS3: internal functions protected function someFunction():void { var internalFunction:Function = function(text:String):void { trace(text); }; internalFunction("Hello World!"); } 14©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  15. 15. AS3: custom namespaces (by Mihai Corlan) // online.as file package org.corlan { public namespace online = "http://corlan.org/apps/online"; } // offline.as file package org.corlan { public namespace offline = "http://corlan.org/apps/offline"; } 15©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  16. 16. AS3: custom namespaces (by Mihai Corlan) online function save(object:Object):void { //save the object back to server trace("online"); } offline function save(object:Object):void { //save the object locally trace("offline"); } ... online::save(obj); offline::save(obj); 16©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  17. 17. AS3: Proxy class dynamic class MyProxy extends Proxy { flash_proxy override function callProperty(name:*, ...rest):* { // function call proxy } flash_proxy override function getProperty(name:*):* { // getter call proxy } flash_proxy override function setProperty(name:*, value:*):void { // setter call proxy } } 17©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  18. 18. ******** /**///// /** ** ** /******* //** ** /**//// //*** /** **/** /** ** //** // // // 18©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  19. 19. Fx: ObjectProxy class warning: unable to bind to property propName on class Object (class is not an IEventDispatcher) 19©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  20. 20. Fx: ObjectProxy class warning: unable to bind to property propName on class Object (class is not an IEventDispatcher) 19©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  21. 21. Fx: ObjectProxy class warning: unable to bind to property propName on class Object (class is not an IEventDispatcher) var obj:Object = {propName : “prop value”}; var objProxy:ObjectProxy = new ObjectProxy(obj); ... <s:Label text=”{objProxy.propName}” /> 19©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  22. 22. Fx: <fx:Library> & <fx:Definition> <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark"> <fx:Library> <fx:Definition name="MySquare"> <s:Group> <s:Rect width="100%" height="100%"> <s:stroke> <s:SolidColorStroke color="red"/> </s:stroke> </s:Rect> </s:Group> </fx:Definition> </fx:Library> <fx:MySquare x="0" y="0" height="20" width="20"/> </s:Application> 20©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  23. 23. Fx: <fx:Private> <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark"> <fx:Declarations> </fx:Declarations> <!-- has to be last tag in MXML doc --> <fx:Private> <!-- content must be in XML format --> <Date>10/22/2008</Date> <Author>Nick Danger</Author> </fx:Private> </s:Application> 21©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  24. 24. Fx: <fx:Reparent> <s:states> <s:State name="portrait" /> <s:State name="landscape" /> </s:states> <s:VGroup includeIn="portrait" width="100%" height="100%"> <s:Rect id="redRect" includeIn="portrait" width="100%" height="100%"> <s:fill> <s:SolidColor color="#FF0000" /> </s:fill> </s:Rect> <s:Rect id="blackRect" includeIn="portrait" width="100%" height="100%"> <s:fill> <s:SolidColor color="#000000" /> </s:fill> </s:Rect> </s:VGroup> <s:HGroup includeIn="landscape" width="100%" height="100%"> <fx:Reparent target="redRect" includeIn="landscape" /> <fx:Reparent target="blackRect" includeIn="landscape" /> </s:HGroup> 22©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  25. 25. Fx: states (by Steve Hartley) <s:states> <s:State name="portrait" /> <s:State name="landscape" /> </s:states> <s:Group width="100%" height="100%"> <s:layout.portrait> <s:VerticalLayout /> </s:layout.portrait> <s:layout.landscape> <s:HorizontalLayout /> </s:layout.landscape> <fx:RedRectangle width="100%" height="100%" /> <fx:BlackRectangle width="100%" height="100%" /> </s:Group> 23©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  26. 26. Fx: state groups (by Narciso (nj) Jaramillo) <s:states> <s:State name="portraitPhone" stateGroups="portrait,phone" /> <s:State name="landscapePhone" stateGroups="landscape,phone" /> <s:State name="portraitTablet" stateGroups="portrait,tablet" /> <s:State name="landscapeTablet" stateGroups="landscape,tablet" /> </s:states> <s:ViewNavigator id="mainNavigator" left="0" left.landscapeTablet="{LIST_WIDTH}" top="0" top.portraitTablet="{ACTIONBAR_HEIGHT + LIST_HEIGHT}" right="0" bottom="0" firstView="views.SummaryView" firstView.tablet="views.DetailView” /> 24©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  27. 27. Fx: IMXMLObject package { import mx.core.IMXMLObject; public class MyMXMLObject implements IMXMLObject { public function initialized(document:Object, id:String):void { trace("Added to:", document, "with id:", id); } } } ... <fx:Declarations> <local:MyMXMLObject id="myMXMLObject" /> </fx:Declarations> 25©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  28. 28. Fx: FlexGlobals.topApplication <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"> <fx:Declarations> <fx:String id="myString">Hello World?!</fx:String> </fx:Declarations> </s:Application> 26©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  29. 29. Fx: FlexGlobals.topApplication <?xml version="1.0" encoding="utf-8"?> <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" title="FlexGlobals" xmlns:local="*" creationComplete="view_creationCompleteHandler(event)"> <fx:Script> <![CDATA[ import mx.core.FlexGlobals; import mx.events.FlexEvent; protected function view_creationCompleteHandler(event:FlexEvent):void { lbl.text = FlexGlobals.topLevelApplication.myString; } ]]> </fx:Script> <s:Label id="lbl" verticalCenter="0" horizontalCenter="0" /> </s:View> 27©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  30. 30. Fx: conditional compilation CONFIG::android protected function view_creationCompleteHandler(event:FlexEvent):void { lbl.text = "Android: " + FlexGlobals.topLevelApplication.myString; } CONFIG::ios protected function view_creationCompleteHandler(event:FlexEvent):void { lbl.text = "iOS: " + FlexGlobals.topLevelApplication.myString; } 28©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  31. 31. Fx: conditional compilation 29©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  32. 32. FB: keeping generated ActionScript 30©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  33. 33. ******** ****** /**///// /*////** /** /* /** /******* /****** /**//// /*//// ** /** /* /** /** /******* // /////// 31©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  34. 34. FB: Press Ctrl+Space to invoke Content Assist. 32©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  35. 35. FB: Metadata code completion 33©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  36. 36. FB: Code completion when using states 34©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  37. 37. FB: Camel-case code hinting 35©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  38. 38. FB: Quick Assist - Press Cmd/Ctrl+1 * Rename in file * Rename in workspace * Generate getter/setter * Convert local variable to field * Assign to variable * Split variable declaration * Organize imports 36©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  39. 39. FB: Quick Outline - Press Cmd/Ctrl+O 37©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  40. 40. FB: Code templates 38©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  41. 41. FB: Organize imports Place your cursor on an import statement, press Cmd/Ctrl+1, and select Organize Imports. To sort the import statements alphabetically by package name, press Cmd/Ctrl+Shift+O. 39©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  42. 42. FB: Call Hierarchy (Cmd/Ctrl+Alt+H) 40©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  43. 43. FB: other shortcuts Cmd/Ctrl+I - Fixing indentation Cmd/Ctrl+Shift+C - Code commenting Cmd/Ctrl+Shift+D - Adding CDATA blocks (<![CDATA[ ]]>) Cmd/Ctrl+Shift+F - Format MXML documents - Block selection and edit mode Cmd/Ctrl+Shift+L - Complete list of shortcuts 41©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  44. 44. ©2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

×