3 Replies Latest reply on Sep 15, 2008 6:33 PM by manofspirit

    Flex FAQ

    Level 7
      Q: I want to use an XML data source to dynamically display images and
      data in my Flex application. I won't know how many images/data points I
      will have at design time. How can I best approach this?

      A: Depending on what you're wanting to do, you can either use a
      Repeater with an Image or custom component that contains an Image or you can
      use a List based component to display an Image or custom component with an
      Image (or SwfLoader, or Loader) in it. The Help is full of resources on
      this subject. Here are some places you may want to try:

      Help>Flex Start Page>Creating a Simple RIA
      Help>Help Contents>User Interfaces
      - Using Data Providers and Collections
      - Controls
      - Image
      - SwfLoader
      - Using Data Driven Controls
      - Using Item Renderers and Item Editors
      - Dynamically Repeating Controls and Containers

      Here is an example that might get you running fast if you find it easier to
      learn from a working example than from Help files:

      Q: I've created a custom itemRenderer component to use in a List
      based component (Datagrid, TileList, HorizontalList, etc.). When my List
      first displays, everything looks fine, but when I scroll it or change the
      dataProvider, some of the itemRenderers show values or formatting that
      aren't right. How do I fix this?

      A: List-based components don't draw a renderer for every item in the
      dataProvider. Instead, they create enough to display what is on screen now,
      plus one or two more waiting in the wings. This means they recycle the
      renderers rather than creating new ones when you change dataProvider or
      scroll up and down. When you use a creationComplete event to set up the
      itemRenderer, that event doesn't happen again when the renderer is used for
      a different set of data. The solution to this is to override the set data
      protected function that most components have.

      For more information, check out the following resources:

      Q: I want to run a function in my main application from inside my
      custom component. But when I try to refer to myFunction() in that
      component, I get a compile time error "Call to a possibly undefined function
      myFunction." How can I fix this?

      A: Your component has its own scope, so it doesn't know anything
      about the functions in the main file. You can get around this by directly
      referencing the main application scope like this:
      Application.application.myFunction(). However, this makes your component
      tightly coupled, which is a quick way of saying that your component is only
      usable in an application that has a myFunction() function in it. You're
      better off dispatching an event from your component and letting the
      application decide how to handle it. For more information, check out the
      following resources:

      Q: I want to decide at runtime what kind of component to add to
      display my data. How can I accomplish this?

      A: Use getDefinitionByName and ClassFactory to dynamically create
      your class. Just be sure that you actually have at least one "hard"
      reference to each class you intend to use, or the class might not get
      compiled into your swf. Here's a full write-up of how to do that:

      Q: I need to set a property or add an event listener on a component
      that is in a ViewStack/TabNavigator/Accordion. When the component is not
      the first child of the Navigator Container, I get a null object error
      (#1009). What causes this, and how can I fix it?

      A: By default, the Navigator containers only create the children of
      each pane as that pane is viewed. The easy way to fix this is to set the
      creationPolicy on the Navigator to "all." However, this will cause your
      application to take longer to load. A better way to fix this is to wait for
      a later event, such as creationComplete on the component you want to access,
      or to use binding to "pull" the data into the component.
      The way I handle it is to call invalidateProperties() on change of the
      ViewStack. I then override commitProperties() and call an "initializer" for
      each pane. In the body of each initializer function, I check to see if the
      selectedItem for the viewStack is the one my initalizer cares about. If
      not, I return from the function immediately. Inside that initializer
      function, I set properties and add listeners as appropriate.

      Q: When my application is taller than the browser window, I get
      scrollbars in the application. I want the browser to do the scrolling. How
      can I do this?

      A: In the html-template/index.template.html file change line 46 (in
      the Flex 3 template) to read <body scroll="auto"> instead of the default of
      <body scroll="no">.

      Q: I am using URLRequest, HTTPRequest, or HTTPService to retrieve
      information from a database on a server. The first time my application
      makes a server call, it works fine. But when I call the same page again, I
      get the same data, even though I know the data has changed on the server.
      Is this a bug?

      A: The browser has cached the response it got from the first call
      you made to the page. This means that you need to either change how you are
      calling the page so it appears to be a new request, or you need to change
      the page itself so that it won't be cached.

      To change how you are calling the page, append a unique value to the end of
      the URL. For example, new URLRequest('yourPage.asp?param="+(new

      If you want to change the page itself, you need to change the response
      headers. The method for changing the response headers will vary from
      language to language. For more on this see:


      Courtesy of Amy's Flex Diary ( http://flexdiary.blogspot.com)

      You can always find the most recent version of this document here: