4 Replies Latest reply on Jul 1, 2009 12:27 PM by razor7_996

    Cant access itemrenderer methods

    razor7_996

      Hello guys, i have this custom components with an item renderer

      <mx:TileList xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:mgs="componentes.*">
         <mx:itemRenderer>
         <mx:Component>
            <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" paddingBottom="0" paddingTop="0" width="100%">
               <mx:Script>
                  <![CDATA[
                     public function get cyclesValue():uint
                     {
                        return cycles.value;
                     }         
      
                     public function set cyclesValue(repeat:uint):void
                     {
                        cycles.value=repeat;
                     }         
                  ]]>
               </mx:Script>
                  <mx:VBox width="225" verticalScrollPolicy="off" horizontalScrollPolicy="off">
                     <mx:Label text="Video: {data.nombreVideo}" />
                     <mx:Label text="Sonido: {data.nombreSonido}" />
                  </mx:VBox>
                  <mx:VBox width="45" height="100%" horizontalAlign="center">
                     <mx:Label text="Repetir"  fontFamily="Verdana" fontSize="10" fontWeight="bold"/>
                     <mx:NumericStepper width="45" minimum="0" value="1" maxChars="2" maximum="99" id="cycles"/>
                  </mx:VBox>
            </mx:HBox>
         </mx:Component>
         </mx:itemRenderer>
      </mx:TileList>
      

      The problem arrises when i want to call the methods within the component, from my main actionscript file, like this:

      private function up():void
      {
             var item:IListItemRenderer = playlist.indexToItemRenderer(playlist.selectedIndex);
            item.cyclesValue(item.cyclesValue()+1);
      }
      
      private function down():void
      {
             var item:IListItemRenderer = playlist.indexToItemRenderer(playlist.selectedIndex);
            item.cyclesValue(item.cyclesValue()-1);
      }
      

      This arrises this error

       

      1061: Call to a possibly undefined method cyclesValue through a reference with static type mx.controls.listClasses:IListItemRenderer

      Any ideas on what i´m doing wrong here?

       

      Thanks a lot!

        • 1. Re: Cant access itemrenderer methods
          eberman Level 1
          I don't know the name of your component, so I'm using "YourComponent" for this example.
          Try this, replacing your component's actual name where I've used "YourComponent".

          var item:YourComponent = playlist.indexToItemRenderer(playlist.selectedIndex) as YourComponent;
          • 2. Re: Cant access itemrenderer methods
            razor7_996 Level 1

            hello...thanks a lot for the reply

             

            i have written this

            var item:playlistItem = playlist.indexToItemRenderer(playlist.selectedIndex) as playlistItem;
            item.cyclesValue(miniaturas.getItemAt(playlist.selectedIndex).ciclos);
            

            but i get the same error

            1061: Call to a possibly undefined method cyclesValue through a reference with static type...
            

            I have changed my itemrenderer to be binded with an arraycollection values from my root code script, so it looks like this

            <?xml version="1.0" encoding="utf-8"?>
            <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" paddingBottom="0" paddingTop="0" width="100%" dataChange="validateNow()">
                 <mx:Script>
                      <![CDATA[
                           import mx.events.NumericStepperEvent;
                        import mx.events.FlexEvent;
            
                           public function set cyclesValue(v:uint):void
                           {
                                cycles.value=v;
                           
                           }
                           
                        private function cyclesChange(e:mx.events.NumericStepperEvent):void
                        {
                             data.ciclos=cycles.value;
                            trace ("Ciclos: " + data.ciclos);
                        }   
                      ]]>
                 </mx:Script>
                 <!-- <mx:Image source="{data.bitmap}" toolTip="{data.cuePointTime}" maintainAspectRatio="true" scaleX="0.38" scaleY="0.38" />-->
                 <mx:VBox width="220" verticalScrollPolicy="off" horizontalScrollPolicy="off">
                      <mx:Label text="Video:  {data.nombreVideo}" />
                      <mx:Label text="Sonido: {data.nombreSonido}" />
                 </mx:VBox>
                 <mx:VBox width="50" height="100%" horizontalAlign="center">
                      <mx:Label text="Repetir"  fontFamily="Verdana" fontSize="10" fontWeight="bold"/>
                      <mx:NumericStepper width="45" minimum="0" value="{data.ciclos}" maxChars="2" maximum="99" id="cycles" change="cyclesChange(event)"/>
                 </mx:VBox>
            </mx:HBox>
            

            As you can see...i want to update the "cycles" value when the array collection changes, also i want to update the "ciclos" field in a given item of the array collection when a click in the numericstepper is done.

             

            So far, when the numericstepper changes, it updates the arraycollection field, but, if i change the array collection field, that change is not reflected in the numericstepper value...it is not changed!!!

             

            Please advise.

             

            Thanks a lot!

            • 3. Re: Cant access itemrenderer methods
              eberman Level 1

              You're using the set method for cyclesValue incorrectly.

              Try:

              item.cyclesValue = miniaturas.getItemAt(playlist.selectedIndex).ciclos;
              • 4. Re: Cant access itemrenderer methods
                razor7_996 Level 1

                yes....you are right, doing this works!

                 

                    var item:playlistItem = playlist.indexToItemRenderer(playlist.selectedIndex) as playlistItem;
                    item.cyclesValue=c;
                

                 

                Where playlistItem is my custom MXML iterenderer file and cyclesValue getter/setter is defined this way

                public function set cyclesValue(v:uint):void
                {
                     cycles.value=v;
                }
                public function get cyclesValue():uint
                {
                     return cycles.value;
                }