thanks a ton Alex..
I don't see anything wrong with my avatarHolder's code.. still pasting the
code here.
Please see the code of "my avatarHolder" ..i think your thoughtful eyes can
catch a loophole...
I am just want my code to be seen by the experience ppl here.. as i don't
have anything to validate it.
so please help me out..
----------------------------------------------
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import ms.imfusion.util.MsLogger;
import mx.core.BitmapAsset;
import mx.core.Container;
import mx.core.UIComponent;
import mx.states.RemoveChild;
public class ImageHolder extends Container
{
private var loader:Loader;
private var myBitmap:Bitmap;
private var imageSrc:String;
private var imageSprite:Sprite;
private var request:URLRequest;
private var uiComp:UIComponent
function ImageHolder(){
super();
setStyle("borderColor","#989898");
setStyle("borderStyle","solid");
setStyle("borderAlpha","0");
setStyle("cornerRadius",3);
setStyle("dropShadowEnabled","true");
createControls()
}
[Bindable]
public function set imageSource(img:String):void{
try{
imageSrc = img;
imageSprite = new Sprite();
//trace("before loading an image imageSrc : " +
imageSrc);
request = new URLRequest(imageSrc);
loader.contentLoaderInfo.addEventListener(
Event.COMPLETE, completeHandler);
loader.contentLoaderInfo.addEventListener(
IOErrorEvent.IO_ERROR,function (){
MsLogger.getInstance().Log(this,"URL not found");
})
loader.load(request);
//trace("after loading an image imageSrc: " +
imageSrc);
imageSprite.visible = false;
imageSprite.addChild(loader);
}
catch(e:Error){
MsLogger.getInstance().Log(this,e.message,"unable to
load image");
}
}
public function unloadImage(){
//removeChild(uiComp)
loader.unload();
}
private function createControls():void{
imageSprite = new Sprite();
loader = new Loader();
}
private function completeHandler(event:Event){
try{
//trace("completeHandler an image imageSrc : " +
imageSrc);
var loader:Loader = Loader(event.target.loader);
var myBitmapData:BitmapData = Bitmap(loader.content
).bitmapData
var myBitmapDataAsset:BitmapAsset = new
BitmapAsset(myBitmapData);
imageSprite.addChild(myBitmapDataAsset);
uiComp = new UIComponent();
imageSprite.visible= true;
uiComp.addChild(imageSprite)
addChild(uiComp);
this.visible = true;
}
catch(e:Error){
//trace("in completeHandler unable to load image");
MsLogger.getInstance().Log(this,e.message,"in
completeHandler unable to load image");
}
}
override protected function
updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth,unscaledHeight);
if(uiComp!=null){
uiComp.x = (this.unscaledWidth - imageSprite.width
)/2;
uiComp.y = (this.unscaledHeight - imageSprite.height
)/2;
}
}
}
}
----------------------------------------------
I will incorporate all your suggestion...
and let me read the doc again...
Thanks a ton..
I really appreciate your interest in solving our queries.. that helps a lot
to dumbs like me...
PS.
On Feb 16, 2008 12:11 AM, Alex Harui <[EMAIL PROTECTED]> wrote:
> Not bad for a first try.
>
>
>
> I would:
>
> 1) extend UIComponent instead of Canvas. You aren't using any of Canvas's
> features so you'll save on size and performance
>
> 2) only call invalidateProperties() in the data setter. Move the code in
> there to commitProperties instead. That'll probably remove the need for the
> try/catch block. The way it is coded now, you'll get exceptions if the data
> setter is run before child objects have been set up in createChildren
>
> 3) Move the positioning of your components to updateDisplayList().
>
> 4) Calculate measuredWidth/Height in measure(), but you shouldn't set x,y
> there as you may not actually be sized to your measured size and in general,
> you'll probably want to react to that in updateDisplayList(). The measure
> method should compute measuredWidth/Height from the
> getExplicitOrMeasuredWidth/Height of the child components plus any spacing
> and gap styles or properties.
>
> 5) not bother to set the avatarholder's imagesource in measure(). If
> these are external images, they won't be measureable in measure() because
> loading external images is asynchronous.
>
>
>
> I don't see any particular reason for why your images end up on the wrong
> row. Maybe there's some problem with AvatarHolder?
>
>
>
> The 'template' for this is in our docs. I'm sure our doc team would love
> to know why the docs weren't clear enough for you.
>
>
>
> -Alex
>
>
> ------------------------------
>
> *From:* [email protected] [mailto:
> [EMAIL PROTECTED] *On Behalf Of *learner
> *Sent:* Friday, February 15, 2008 12:52 AM
> *To:* [EMAIL PROTECTED]; [email protected]
> *Subject:* [flexcomponents] simple renderer please help..........please
> review it
>
>
>
> Hi all,
> I am doing my constant effort to learn and make a decent item renderer for
> a list ..
> I have also attached a code that i have written for it...
> please please have a look at it and tell me where i am doing wrong and
> loopholes are...
>
> the problem that i am facing is ;
> in my image holder the images are not shown properly ... meaning
> sometimes the image from the different row gets displayed in the other row..
> I guessed that there is a way in which u can cache the bitmap in image
> holder and things like that.. don't know in details ...
>
> can any body please suggest me the proper way to design a renderer for
> this.. please review the following code...
>
> (Would be a great help if any body can design this properly for me...i
> know its too much too ask.. but that will give me guideline and a sort of
> template .
> And I once for all ,will get the authentic way to make renderer...till
> this time .. for me its just blind chess which has really exhausted me
> )
>
> Thanks
>
> my item rendere contains :
> 1) image..
> 2) a text comming next to image
> 3) a text comming below the text in 2)
>
> (Code file is attached)
> package ms.messengermodule
> {
> import mx.containers.Canvas;
> import mx.controls.Image;
> import mx.controls.Label;
>
> public class ContactBox extends Canvas
> {
>
> /*private var memberStatus:Label;*/
>
> [Embed(source='style.swf', symbol='memberOnline')]
> private var onlineIcon:Class;
>
> [Embed(source='style.swf', symbol='memberOffline')]
> private var offlineIcon:Class;
>
> [Embed(source='ms/felix/css
>
> /assets/felixStyle.swf', symbol='memberBusy')]
> private var busyIcon:Class;
>
> [Embed(source='style.swf', symbol='organizer')]
> private var organizerIcon:Class;
>
> private var memberName:Label;
>
> private var memberDescription1:Label;
> private var memberDescription2:Label;
> private var memberDescription3:Label;
>
> private var avatarHolder:ImageHolder;
>
> private var description1:String;
> private var description2:String;
> private var description3:String;
>
> private var contactObject:ContactObject;
> private var statusImage:Image;
> private var statusIcon:Object;
> private var memberNamestr:String;
> private var userImage:String;
>
> /**
> * Constructor
> */
> function ContactBox() {
> super();
> this.horizontalScrollPolicy = "off";
> this.verticalScrollPolicy = "off";
>
> }
>
> override public function set data(value:Object):void {
> try{
> super.data = value;
> contactObject = value as ContactObject;
> description1 = contactObject.extensionObject["E"]; // take
> the value from some dictinory object
> memberNamestr = contactObject.name.split(" ")[0];
> userImage = contactObject.imageUrl; // user image
> statusIcon = "";
> getStatusIcon();
> invalidateProperties();
> }
> catch(e:Error){
> trace(e.message);
> }
> }
>
>
>
> private function getStatusIcon():void {
> if(contactObject.presence == Constants.Online_Presence){
> statusIcon = new onlineIcon() ;
> }
> if(contactObject.presence == Constants.offline_Presence){
> statusIcon = new offlineIcon();
> }
> if(contactObject.presence == Constants.Busy_Presence){
> statusIcon = new busyIcon();
> }
> }
>
>
>
> override protected function createChildren():void {
>
> avatarHolder = new ImageHolder();
> addChild(avatarHolder);
> avatarHolder.height = 38;
> avatarHolder.width = 38;
> //avatarHolder.imageSource = "";
>
> memberName = new Label();
> memberName.styleName = "NormalTextBoldSmall"
> memberName.setStyle("color","0xbababa");
> memberName.text="";
> addChild(memberName);
>
> memberDescription1 = new Label();
> memberDescription1.styleName = "NormalText";
> memberDescription1.setStyle("fontWeight","normal");
> memberDescription1.text=""
> addChild(memberDescription1);
>
> memberDescription2 = new Label();
> memberDescription2.styleName = "NormalTextSmall";
> memberDescription2.text=""
> addChild(memberDescription2);
>
> memberDescription3 = new Label();
> memberDescription3.styleName = "NormalTextSmall";
> memberDescription3.text=""
> addChild(memberDescription3);
>
> statusImage = new Image();
> addChild(statusImage);
> statusImage.height = 10;
> statusImage.width = 10;
> super.createChildren();
> this.styleName="messengerlistRenderer";
> }
>
>
>
>
> override protected function measure():void{
> //trace(" measure MemberBox"+ memberObject.name);
> super.measure();
> memberName.text = memberNamestr//contactObject.name;
>
> avatarHolder.x = 0;
> avatarHolder.y=0;
> avatarHolder.imageSource = contactObject.imageUrl;
>
> memberName.width = 100
> memberDescription1.width = 150;
> memberName.x = avatarHolder.width + avatarHolder.x + 4;
> memberDescription1.htmlText =
> description1//contactObject.discription1;
> memberDescription1.x = memberName.x;
>
> memberDescription1.y = memberName.textHeight+5;
>
> var memberWidth:Number = (memberName.textWidth>
> memberWidth)?memberWidth:memberName.textWidth
>
> statusImage.x = memberName.x + memberWidth+ 10;
> statusImage.y = memberName.y + 5;
>
>
> }
>
> override protected function commitProperties():void {
> memberDescription1.htmlText =
> description1//contactObject.extensionObjectArray[Constants.D_EVENT_NAME];
> memberName.text = contactObject.name;
> statusImage.source = statusIcon;
> avatarHolder.unloadImage();
> //avatarHolder.visible = false;
> avatarHolder.imageSource = contactObject.imageUrl;
> statusImage.source = statusIcon;
> super.commitProperties();
> //trace(" commitProperties MemberBox"+ memberObject.name);
> }
>
>
> }
> }
>
> Regards
> PS
>
>
>