3 Replies Latest reply on Oct 12, 2010 1:15 AM by Scaljeri

    Custom Itemrenderer MXML, but cannot access 'data' in AS

    Scaljeri

      Hi All

       

      I've written a simple mxml Itemrenderer. Here is a simplified version

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

         <mx:Image source="{data.url}>

      </mx:Canvas>

       

      Now I want to add the image using actionScript. This is what I've tried (and doesn't work):

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

         <mx:Script>

            <![CDATA[

               override protected function createChildren():void 

                { 

                     super.createChildren();

                     this.addChild(this.data.img) ; // with 'img' being an Image object

                }

            ]]>

          </mx:Script>

      </mx:Canvas>

       

      The problem is that this.data does not contain img and also no url property so I must do something wrong accessing the properties of this object

      Any suggestions ?

       

      thnx

      Luca

       

      ps here is a snippet of the class definition of the object behind 'data'

       

      public class MyClass {

            public function MyClass(){ .. }

       

             public function get url():String

              {

                  return "http://someURL/img.jpg";

              }

       

       

             public function get img():Image {

                return photo ;

             }

      }