1 Reply Latest reply on May 26, 2008 10:37 PM by Gregory Lafrance

    Problems with itemRenderer

    cheftimo Level 2
      Hello,

      Here is an itemRenderer for a TileList, a simple custom component (not an inline renderer). I'm having problems accessing properties in the main application file.

      The code works fine, now what I need to do is get the value of 'locale', which is set in the main application where the tile list is used. So the first line of the code, I think should be
      private var locale:String = outerDocument.locale;

      'locale' is set as a public var in the main application.

      The compiler error is 'Access of undefined property outerDocument', but according to the Flex docs this should work. Just in case, I have also tried: Application.locale, Application.application.locale, parentDocument.locale and several other with no success.

      What else should I try?

      Carlos

        • 1. Re: Problems with itemRenderer
          Gregory Lafrance Level 6
          This seems to work:

          ------------- components.TestComp1.mxml ------------
          <?xml version="1.0" ?>
          <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml">
          <mx:Image id="image" width="60" height="60" source="{data.image + '_150.jpg'}"/>
          <mx:Text text="{setCaption()}"/>
          <mx:Script>
          <![CDATA[
          import mx.core.Application;
          private var locale:String = Application.application.locale;

          private function setCaption():String{
          if (locale == "en_US"){
          return "caption_en_US";
          }else{
          return "caption_es_CO";
          }
          }
          ]]>
          </mx:Script>
          </mx:VBox>
          ---------------- Test.mxml -----------------
          <?xml version="1.0"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
          <mx:Script>
          <![CDATA[
          public var locale:String = "en_US";

          [Bindable]
          public var xmlData:XML =
          <items>
          <item>
          <caption>Paris Caption</caption>
          <image>ParisNight</image>
          </item>
          <item>
          <caption>Rome Caption</caption>
          <image>RomeMidday</image>
          </item>
          </items>;
          ]]>
          </mx:Script>
          <mx:HorizontalList id="myList"
          columnWidth="125"
          rowHeight="125"
          columnCount="4"
          dataProvider="{xmlData.item}"
          itemRenderer="components.TestComp1"/>
          </mx:Application>