1 Reply Latest reply on Aug 3, 2009 12:30 PM by Handycam

    Pass a value to an item renderer button

    Handycam Level 1

      I have a datagrid.  One of the columns has a value of "@recipe", with is a string that's a URL.

       

      I need to replace this with a link button that goes to this url.

       

      So I created an Item Renderer:

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
      <mx:Script>
           <![CDATA[
                private var linkToGoTo:String = XML(data).@recipe
      
                private function goRecipe(event:MouseEvent):void {
                trace("Link="+linkToGoTo);
                }
           ]]>
      </mx:Script>
      <mx:LinkButton id="related" label="Related Recipe" click="goRecipe(event)" />
      </mx:Canvas>
      

       

      Problem is that I am not getting my XML value.   If I did this:

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
      <mx:Script>
           <![CDATA[
                private function goRecipe(event:MouseEvent):void {
                trace(event.currentTarget.label);
                }
           ]]>
      </mx:Script>
      <mx:LinkButton id="related" label="{XML(data).@recipe}" click="goRecipe(event)" />
      </mx:Canvas>
      

      This works, but of course I do not want the label to be this long URL.  How would I do this?

        • 1. Re: Pass a value to an item renderer button
          Handycam Level 1

          OK, I got it to work like this, not sure if it's the best way:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
          <mx:Script>
               <![CDATA[
                    private var relatedRecipe:String
                    
                    override public function set data(value:Object):void
                    {
                  if(value != null)
                  {
                     super.data = value;
                     relatedRecipe = value.@recipe
                     if (relatedRecipe.length>1) {
                          trace("recipe="+relatedRecipe);
                          related.visible = true;
                     } else {
                          related.visible = false;
                     }
                       }   
                    }
               
                  private function goRecipe(event:MouseEvent):void {
                       var linkToGoTo:URLRequest = new URLRequest(relatedRecipe);
                       navigateToURL(linkToGoTo, "_blank");
                    }
               ]]>
          </mx:Script>
          <mx:LinkButton id="related" label="Related Recipe" click="goRecipe(event)" textDecoration="underline" fontSize="10" styleName="recipeLinkButton" />
          </mx:Canvas>