2 Replies Latest reply on Aug 26, 2010 7:06 AM by BorekB

    Custom MX item renderer with 'text' property

    BorekB Level 1

      I'm trying to do something like

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                    xmlns:s="library://ns.adobe.com/flex/spark" 
                    xmlns:mx="library://ns.adobe.com/flex/mx" 
                    focusEnabled="true">
        
        <fx:Script>
          <![CDATA[
            
            [Bindable] // would be defined in <fx:Binding>
            override public function get text():String {
              return myTextInput.text;
            }
            
            public function set text(value:String):void {
              myTextInput.text = value;
            }
      
          ]]>
        </fx:Script>
      
        
        <s:TextInput id="myTextInput" ... />
      </s:MXDataGridItemRenderer>
      
      

       

      This will show an error "Method marked override must override another method" which probably points to the setter (compiler doesn't show a line number in this case). As the setter is not defined in the ancestor (MXItemRenderer), adding "override" to it causes the same error. Last try is to remove the override keyword from the getter but that naturally causes "Overriding a function that is not marked for override" error.

       

      I'd like to use the 'text' property as that works best in item editors but is there a way in AS3 to overcome this problem when an ancestor defines only one of the getters/setters but I need to use both?

        • 1. Re: Custom MX item renderer with 'text' property
          ShardulSingh Level 3

          Hi pls try like this it will work,and let me know if you have any issue.

           

          Item renderer

          <?xml version="1.0" encoding="utf-8"?>
          <s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                                    xmlns:s="library://ns.adobe.com/flex/spark"
                                    xmlns:mx="library://ns.adobe.com/flex/mx"
                                    focusEnabled="true">
             
              <fx:Script>
                  <![CDATA[
                      override public  function set data(value:Object):void
                      {
                          super.data = value;
                          txt.text = data.text;
                      }
                  ]]>
              </fx:Script>
             
              <s:TextInput id="txt"/>
             
          </s:MXDataGridItemRenderer>

           

           

          Main Application

          <?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"
                         xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                         >
             
              <fx:Declarations>
                  <!-- Place non-visual elements (e.g., services, value objects) here -->
              </fx:Declarations>
             
              <fx:Script>
                  <![CDATA[
                      import mx.collections.ArrayCollection;
                     
                      [Bindable]
                      private var ac : ArrayCollection = new ArrayCollection([
                          {name : 'Rober',phone : '895674',text : 'text 1'},
                          {name : 'John',phone : '895674',text : 'text 2'},
                          {name : 'Peter',phone : '895674',text : 'text 3'},
                          {name : 'Albert',phone : '895674',text : 'text 4'},
                         
                      ])
                  ]]>
              </fx:Script>
             
             
              <mx:DataGrid id="dg" width="100%" height="100%" rowCount="5" dataProvider="{ac}">
                  <mx:columns>
                      <mx:DataGridColumn dataField="name" headerText="Name"/>
                      <mx:DataGridColumn dataField="phone" headerText="Phone"/>
                      <mx:DataGridColumn itemRenderer="MXDataGridItemRenderer"/>
                  </mx:columns>
              </mx:DataGrid>
          </s:Application>

           

           

           

           

           

           

           

           

          with Regards,

           

          Shardul Singh Bartwal

          • 2. Re: Custom MX item renderer with 'text' property
            BorekB Level 1

            I should have stressed that I want to use this component as an item editor, not item renderer (it's slightly confusing that editors derive from MXDataGridItemRenderer). I needed to use another property as editorDataField as it seemed that AS3 compiler won't let me override only getter and not setter.