Thanks a lot Chris, I made some modification to the code below  you gave and it 
did magic for me.
Thanks again.
Anitha.

--- On Sun, 11/22/09, Chris <zomgfore...@gmail.com> wrote:


From: Chris <zomgfore...@gmail.com>
Subject: Re: [flexcoders] Re: Is thereany way using a Image Renderer ,I can 
change the widtth or height of an image?
To: flexcoders@yahoogroups.com
Date: Sunday, November 22, 2009, 11:44 PM


  



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.createChildre n();
        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 <amyblankenship@ bellsouth. net> wrote:


  






--- In flexcod...@yahoogro ups.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