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.

How To Navigate And Extend The Flex Infrastructure


Published on

Published in: Technology, Business

How To Navigate And Extend The Flex Infrastructure

  1. 1. How to Navigate and Extend the Flex Infrastructure Michael Labriola Senior Consultant digital primates IT Consulting Group Adobe Certified Instructor – Flex Adobe Certified Expert – Flex Adobe Community Expert – Flex
  2. 2. Who am I? <ul><li>Senior Consultant @ digital primates IT </li></ul><ul><li>Consulting Group means: </li></ul><ul><ul><li>I spend the majority of my day crawling through the flex infrastructure so I can teach it to others </li></ul></ul><ul><ul><li>I mentor large development teams that need to learn Flex fast when management declares it as a new direction </li></ul></ul><ul><ul><li>I am responsible for writing code that will someday be cloned thousands of times with little regard to the initial context </li></ul></ul>
  3. 3. Who am I? <ul><li>Reverse Engineer </li></ul><ul><ul><li>Deciphering how someone else’s micro-controller was programmed with an oscilloscope and a lot of Mountain Dew ® </li></ul></ul><ul><ul><li>Reading and rewriting 68k opcodes in hex </li></ul></ul><ul><ul><li>Learning through pure induction, all day, every day </li></ul></ul>
  4. 4. What is Flex? <ul><li>Flex is a product developed by Adobe which allows developers to create rich Internet applications that run in the flash player. </li></ul><ul><ul><li>Flex solves some of the frustration traditional application developers encounter when trying to create applications in Flash </li></ul></ul><ul><ul><li>Flex is generally written using two languages </li></ul></ul><ul><ul><ul><li>MXML – An XML tag based language used to define the visual layout </li></ul></ul></ul><ul><ul><ul><li>ActionScript 3 – A newer generation of the actionscript language familiar to those with a flash background </li></ul></ul></ul>
  5. 5. What are we going to talk about? <ul><li>If you give a man a fish, he will have a single meal. If you teach him to fish, he will eat all his life. </li></ul><ul><ul><li>Sure, this saying is overused but the concept is important </li></ul></ul><ul><ul><li>I am not planning on teaching how to program a Flex component… I want to teach you how to figure it out on your own </li></ul></ul>
  6. 6. What are we going to talk about? <ul><li>Knowing how to solve a problem is more important than having the solution </li></ul><ul><ul><li>I think this applies to Flex… </li></ul></ul><ul><ul><li>Warning: Does not apply in every situation. Great example: lack of a parachute </li></ul></ul>
  7. 7. What are we going to talk about? <ul><li>The solutions already exist, you don’t know where to find them </li></ul><ul><ul><li>There is more information available in terms of code samples, design patterns and general Flex know-how in the framework *already* installed with Flex than any book, blog or doc in the world. </li></ul></ul><ul><ul><li>Why aren’t you using them? </li></ul></ul>
  8. 8. What can we expect? <ul><li>We aren’t going to write code. We are going to read code </li></ul><ul><ul><li>We will review, read and talk about code in the framework and code that I wrote for this session… </li></ul></ul><ul><ul><li>You don’t need to see me type it to make it valid </li></ul></ul><ul><ul><li>I am not going to provide a bunch of rules, I am going to show you where you should look to induce these generalities </li></ul></ul>
  9. 9. What can we expect? <ul><li>Questions </li></ul><ul><ul><li>Please ask when we are covering the topic. </li></ul></ul><ul><ul><li>In this session, depth is more important than breadth. I would rather drop slides off the end and ensure you understand what I do present </li></ul></ul>
  10. 10. Sounds fine, how do we get started? <ul><li>Source Code </li></ul><ul><ul><li>For those of you that don’t know, MXML tags, such as DataGrid and Button, are really just ActionScript classes </li></ul></ul><ul><ul><li>If you want to understand how to make a component that has nodes like the Tree control but moves panes like the Accordion, what better place to look but the source code for these components </li></ul></ul>
  11. 11. Where do we find the source? <ul><li>The Flex Framework </li></ul><ul><ul><li>Flex ships with (almost) all of the source code available for your review </li></ul></ul><ul><ul><li>You can find this code under the Flex Builder 3 installation folder at </li></ul></ul><ul><ul><li>sdks3.0.0frameworksprojectsframeworksrc </li></ul></ul>
  12. 12. How do we get to the source? <ul><li>Linked Folder </li></ul><ul><ul><li>If you feel like being a bit clever (lazy) you can setup a linked folder in your project to the source directory. Doing so will give you quick access to the source </li></ul></ul><ul><ul><li>You can also press </li></ul></ul><ul><ul><li>Control-Shift-T at any time to find a class </li></ul></ul>
  13. 13. How do we get to the source? <ul><li>Organization of Packages </li></ul><ul><ul><li>Flex packages follow a consistent setup </li></ul></ul><ul><ul><li>The majority of components extended by developers reside in controls and containers </li></ul></ul>
  14. 14. How do we know where the code resides? <ul><li>The Help Files </li></ul><ul><ul><li>The Flex help files contain the package information </li></ul></ul>
  15. 15. How do we read the code? <ul><li>Conventions </li></ul><ul><ul><li>Within the framework, coding conventions such as consistent method and variable names are routinely followed </li></ul></ul><ul><ul><li>Comments and compiler metadata are used to add dialogue to the code </li></ul></ul>
  16. 16. What are the conventions? <ul><li>Naming Conventions </li></ul><ul><ul><li>MyClassName – Classes are always mixed case starting with a capital letter </li></ul></ul><ul><ul><li>myMethodName() or myVariableName – Always start lower case </li></ul></ul><ul><ul><li>STATIC_OR_CONST – Always upper case, underscore separated </li></ul></ul>
  17. 17. What else do we need to read the code? <ul><li>Access Control </li></ul><ul><ul><li>internal - (default) Visible to references inside the same package </li></ul></ul><ul><ul><li>private – visible to references inside the same class </li></ul></ul><ul><ul><li>protected – visible to references in the same class and derived classes </li></ul></ul><ul><ul><li>public – visible to references everywhere </li></ul></ul><ul><ul><li>static – specifies that a properties belongs to a class, not an instance </li></ul></ul>
  18. 18. What else do we need to read the code? <ul><li>Namespaces </li></ul><ul><ul><li>Namespaces provide further granularity to the visibility of methods and properties </li></ul></ul><ul><ul><li>use namespace mx_internal; </li></ul></ul><ul><ul><li>mx_internal function columnItemRendererFactory() </li></ul></ul>
  19. 19. Got it. What Else? <ul><li>MetaData Tags </li></ul><ul><ul><li>Reading the metadata tags can often provide as much information as the remainder of the documentation </li></ul></ul>
  20. 20. What If we don’t see what we need? <ul><li>Following Inheritance </li></ul><ul><ul><li>Control+Click or F3 causes Flex Builder to find where a given property was defined </li></ul></ul><ul><ul><li>This is particularly helpful when the property or method was defined in a different class </li></ul></ul>
  21. 21. Is this inheritance documented? <ul><li>Just as the help files show the package name, they also show the inheritance chain and where a property was originally declared </li></ul>
  22. 22. How far does it go? <ul><li>While the majority of the source code is available for your review, event dispatching and some other low level items are not present as source code </li></ul>
  23. 23. That’s it? <ul><li>Viewing code without a concept of order is useless </li></ul><ul><ul><li>Flex Components startup and execute in a very specific order, often called the component instantiation lifecycle </li></ul></ul><ul><ul><li>This lifecycle consists of a series of methods that are called by the Flex framework, not directly by the developer </li></ul></ul>
  24. 24. What are these methods? <ul><li>The lifecycle methods consist mainly of: </li></ul><ul><ul><li>commitProperties() </li></ul></ul><ul><ul><li>createChildren() </li></ul></ul><ul><ul><li>measure() </li></ul></ul><ul><ul><li>updateDisplayList () </li></ul></ul>
  25. 25. What does commitProperties do? <ul><li>commitProperties commits changes to a component. It is useful for: </li></ul><ul><ul><li>Ensuring changes happen at the same time </li></ul></ul><ul><ul><li>Ensuring that properties are set in a specific order </li></ul></ul><ul><ul><li>Ensuring properties are not set on child objects until the exist </li></ul></ul><ul><ul><li>Reducing code duplication that can occur when dependencies between properties exist </li></ul></ul>
  26. 26. What does createChildren do? <ul><li>createChildren is used to make composite components. It is responsible for: </li></ul><ul><ul><li>instantiating any visual child objects within the component </li></ul></ul><ul><ul><li>createChildren only ensures these children are created, it does NOT deal with layout or sizing </li></ul></ul>
  27. 27. What does measure do? <ul><li>measure helps determine the size of a component </li></ul><ul><ul><li>Calculates the default size/default minimum size of a component. Parent objects have the ultimate say on sizing a component. Measure provides a ‘suggestion’ to the parent of this component </li></ul></ul><ul><ul><li>This method is only called if Flex needs to derive the size. It is not called if a explicit height and width are set </li></ul></ul>
  28. 28. What does updateDisplayList do? <ul><li>updateDisplayList is the workhorse of the Flex component </li></ul><ul><ul><li>Sizes and positions any items created in createChildren </li></ul></ul><ul><ul><li>Also responsible for drawing items like backgrounds or other graphical elements </li></ul></ul><ul><ul><li>When Flex calls updateDisplayList, it provides the width and height actually allocated for your component regardless of scaling </li></ul></ul>
  29. 29. Does that cover what I need to know? <ul><li>The order that these methods are called is still extremely important </li></ul><ul><ul><li>When a component is created either in MXML or ActionScript, the components constructor is always called </li></ul></ul><ul><ul><li><comp:MyComponent/> </li></ul></ul><ul><ul><li>OR </li></ul></ul><ul><ul><li>var comp:MyComponent = new MyComponent(); </li></ul></ul>
  30. 30. What about the rest of the methods? <ul><li>The lifecycle methods begin when a component is added to a container </li></ul><ul><ul><li>When using MXML to add a component, it is generally added to its parent container automatically </li></ul></ul><ul><ul><li>When using ActionScript, the developer manually calls the addChild method </li></ul></ul><ul><ul><li>var comp:MyComponent = new MyComponent(); </li></ul></ul><ul><ul><li>addChild( comp ); </li></ul></ul>
  31. 31. What about the rest of the methods? <ul><li>The lifecycle methods will then generally execute in this order </li></ul><ul><ul><li>commitProperties() </li></ul></ul><ul><ul><li>createChildren() </li></ul></ul><ul><ul><li>measure() </li></ul></ul><ul><ul><li>updateDisplayList() </li></ul></ul>
  32. 32. So these methods are only called once? <ul><li>createChildren() will only be called once, however, the developer can request that the other methods are called at specific times </li></ul><ul><ul><li>Calling invalidateProperties() asks Flex to call commitProperties() </li></ul></ul><ul><ul><li>Calling invalidateSize() asks Flex to call measure() </li></ul></ul><ul><ul><li>Calling invalidateDisplayList() asks Flex to call updateDisplayList() </li></ul></ul>
  33. 33. Why shouldn’t I just call the actual methods? <ul><li>Calling the invalidate* methods asks Flex to call the lifecycle methods at the appropriate time </li></ul><ul><ul><li>By using the invalidate* methods you allow Flex to effectively ‘schedule’ when these methods will be called </li></ul></ul><ul><ul><li>Doing so can increase the responsiveness of your application by decreasing the number of times a these methods are actually invoked </li></ul></ul>
  34. 34. Ok. That’s it, right? <ul><li>Yes, for now. </li></ul><ul><ul><li>Let’s take a tour of the framework and try to solve a real world problem using your newfound knowledge </li></ul></ul>
  35. 35. Review Time <ul><ul><li>The Flex framework has a tremendous amount of code available for review </li></ul></ul><ul><ul><li>It is, in my opinion, the single best way to learn Flex </li></ul></ul><ul><ul><li>Understanding where to look for these solutions means you have a virtually infinite resource of solid code and design patterns </li></ul></ul>
  36. 36. Where to go from here? <ul><ul><li>Read my blog ‘codeSlinger’… because I said so </li></ul></ul><ul><ul><ul><li> </li></ul></ul></ul><ul><ul><li>Everyone at digitalprimates </li></ul></ul><ul><ul><ul><li> </li></ul></ul></ul><ul><ul><li><michigan:FlexCamp/> on July 30 th and 31st </li></ul></ul><ul><ul><ul><li> </li></ul></ul></ul>
  37. 37. How to Navigate and Extend the Flex Infrastructure Michael Labriola Senior Consultant digital primates IT Consulting Group Adobe Certified Instructor – Flex Adobe Certified Expert – Flex Adobe Community Expert – Flex