Looking deeper into your code I noticed:

That you are creating an Image *inside* an Image. There's no need to create
an image inside an image, perhaps you should use one of the more generic
'container' classes inside mx.containers.*. In my example below I chose
Canvas.

You are constructing your image control within your setter for your property
if data is null. Generally, you want to follow the standard practice of
creating your children in the createChildren() method. You'll find that Flex
has more consistent behavior for your custom controls if you do that.

You need to call addChild() on your newly created child otherwise it won't
be placed on the stage.


Here is a modified version of your class that may or may not compile.
Compiling is an exercise to the user. :)

package{

import mx.controls.*;
import mx.core.*;
import mx.containers.Canvas;

public class ImageRenderer extends Canvas implements IDataRenderer
{

    private var slaimage:Image;
    private var _data:Object;

    public function ImageRenderer()
    {
        super();
    }

    override public function createChildren()void
    {
        super.createChildren();
        slaimage = new Image();
        slaimage.width = 15;
        slaimage.height= 15;
        // optional: vertically and horizontally center your image within
the canvas.
        slaimage.setStyle("horizontalCenter", 0);
        slaimage.setStyle("verticalCenter", 0);
        addChild(slaimage); // <-----THIS IS IMPORTANT TO DO
        //if data is set before createChildren() is called, use it.
        if(_data){
            slaimage.source=value.CurrentSLA;
        }
    }

    override public function set data(value:Object) :void
    {
        _data = value;
        if(slaimage){
            slaimage.source=value.CurrentSLA; //only set this if it exists.
If it doesn't, then its being called before createChildren has been called.
        }
    }
}

On Sat, Nov 21, 2009 at 7:29 AM, Amy <amyblankens...@bellsouth.net> wrote:

>
>
>
>
> --- In flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>,
> "mitchgrrt" <mitch_g...@...> wrote:
> >
> > 3. Width and height are properties of Image, not styles, so setStyle()
> > won't work.
>
> You can add code to accept them as styles...
>
>  
>

Reply via email to