1 Reply Latest reply on Jan 26, 2010 3:01 PM by jsd99

    itemRenderer dataChange question

    jsd99 Level 3

      I have a HorizontalList control with a custom ItemRenderer.  I want to display an image (or not) for the particular item.  However, I am having crazy problems getting it to work.  I have an mx:Image MXML component in the file, and a custom method for the dataChange="" event.  I can't access the image in the dataChange method, though.  It isn't defined at runtime.  There must be some sort of weird timing issue.  How do I make this work?

       

      The code looks like this:

       

      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
          borderStyle="none" width="96" horizontalScrollPolicy="off"
          verticalScrollPolicy="off" mouseOver="textChange(event)" mouseOut="textChangeback(event)"
          buttonMode="true" useHandCursor="true" dataChange="resetPlayButton(event)">


          <mx:Script>
              <![CDATA[
                  private function textChangeback(event:MouseEvent):void
                  {
                      thumbLabel.setStyle("color", 0x999999)
                  }
             
                  private function textChange(event:MouseEvent):void
                  {
                      thumbLabel.setStyle("color", 0xFFFFFF)
                  }

       

                  private function resetPlayButton(event:Event):void {           
                      if (data.media_type == 3 || data.site_id == 1) {
                          playButton.visible = true;
                      }
                      else {
                          playButton.visible = false;
                      }
                  }
              ]]>
          </mx:Script>
          <mx:Image id="image" width="80" height="50" source="{data.thumb}"
               horizontalAlign="center" scaleContent="true" maintainAspectRatio="false"
               completeEffect="Fade" y="0" horizontalCenter="-8"/>

       

          <mx:Text id="thumbLabel" text="{data.take_name}" width="80"
              styleName="takeText" addedEffect="Fade" color="#999999"
              buttonMode="true" useHandCursor="true" mouseChildren="false" y="50" horizontalCenter="-8"/>
             
             <mx:Image id="playButton" x="8" y="10" visible="false" source="assets/play-icon-sm.png" />
      </mx:Canvas>

        • 1. Re: itemRenderer dataChange question
          jsd99 Level 3

          I solved it by specifying both dataChange and creationComplete pointing to the same method, and then in the method I just check to see if playButton has been created yet.  If it hasn't I bail out, otherwise I set the property as required.  Seems kind of kludgey to me but it works.