This renderer is based on VBox which is a container and is a bit
"heavy".  I'm guessing that since you are showing movies that there
aren't too many of them, but if there were, you might eventually run
into performance issues.  Lean-and-mean renderers are almost always
written in Actionscript.  On my blog (blogs.adobe.com/aharui) I have
some examples.

 

This renderer also uses states w/o transitions just to switch between
two views.  Renderers get recycled as you scroll and the state switching
could be expensive since add/remove is slower than changing the visible
flag.

 

Because you used a container and are using databinding to fill out the
fields, you probably don't need to override the data setter at all
because commitProperties is probably not needed (in fact, you didn't
implement and override).  You also probably do not have to implement a
mapping to your value object.  You'll save a few microseconds here and
there by doing so, but may not be worth the effort.

 

Thus, in its most reduced form, this renderer could look more like this
(you might need some code for positioning and sizing):

 

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> " width="100" 
height="120" 
horizontalScrollPolicy="off" verticalScrollPolicy="off" 
borderStyle="solid" >
<mx:Script>
<![CDATA[
private function swfLoadHandler(e:Event):void{
var swfContent:MoveClip = e.target.content as MovieClip;
swfContent.stop();
}]]>
</mx:Script>
<mx:Image id="thumbImage" maintainAspectRatio="true" 
source="{'images/'+ data.img}" scaleContent="true" height="95%" 
width="95%" visible="{data.img.length > 0}" x="?" y="?" />
</mx:VBox>
<mx:Label id="theCaption" width="100%" text="{data.caption}" 
textAlign="center"/>
<mx:SWFLoader id="movie" 
source="{'movies/'+data.swf}" maintainAspectRatio="true" width="95%" 
height="95%" scaleContent="true" visible="{data.swf.length > 0}" />
</mx:Canvas>

 

HTH,

-Alex

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of droponrcll
Sent: Monday, October 01, 2007 9:05 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: MultiPurpose ItemRenderer

 

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> Like I said, I'm trying to minimize my time per message and 
generally
> give short answers and leave out detail. Sounds like you're on 
your way
> and that's great.
> 
> 
> 
> Normally, though I don't override data getter/setters in my 
renderers.
> I map the data to a type in commitProperties. But there are 
exceptions
> to every rule... Nevertheless, I am concerned you haven't fully
> absorbed the "recipe" and maybe looking at your code will shed some
> light on it for you and others as there are things you can't do in 
the
> setter override that you should only do in commitProperties or 
later and
> thus your current recipe may not be cloneable on your next renderer.

<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> " width="100" 
height="120" 
horizontalAlign="center" verticalAlign="middle" 
horizontalScrollPolicy="off" verticalScrollPolicy="off" 
borderStyle="solid" >
<mx:Script>
<![CDATA[
import vo.MediaElement;

[Bindable]
private var _img:String;
[Bindable]
private var _swf:String;
[Bindable]
private var _caption:String;
[Bindable]
private var _data:Object;
[Bindable]
private var _mo:MediaElement;
private var swfContent:MovieClip;

private function init():void{
//movie.addEventListener(Event.INIT, 
swfLoadHandler);
}
private function swfLoadHandler(e:Event):void{
swfContent = e.target.content as MovieClip;
swfContent.stop();
}
override public function get data():Object{
return _data;
}
override public function set data(_me:Object):void{
_data = _me;
this.mediaObject = _me as MediaElement;
trace('media element set');
invalidateProperties();
}

public function set mediaObject(me:MediaElement):void{
if (me.imgSrc != ''){
this.imgSrc = me.imgSrc;
}
if (me.swfSrc != ''){
this.swfSrc = me.swfSrc;
}
this.caption = me.caption;
_mo = me;
//invalidateProperties();
}
public function get mediaObject():MediaElement{
return _mo;
}

public function set imgSrc(img:String):void{
_swf = '';
_img = img;
this.currentState="";
}
public function get imgSrc():String{
return _img;
}
public function set swfSrc(swf:String):void{
_img = '';
_swf = swf;
this.currentState="isSwf";

}
public function get swfSrc():String{
return _swf;
}
public function set caption(cstr:String):void{
_caption = cstr;
}
public function get caption():String{
return _caption;
}
]]>
</mx:Script>
<mx:VBox id="viewHolder" horizontalAlign="center" 
verticalAlign="middle" height="100%" width="100%">
<mx:Image id="thumbImage" maintainAspectRatio="true" 
source="{'images/'+_img}" scaleContent="true" height="95%" 
width="95%"/>
</mx:VBox>
<mx:Label id="theCaption" width="100%" text="{_caption}" 
textAlign="center"/>
<mx:states>
<mx:State name="isSwf" enterState="init()">
<mx:AddChild relativeTo="{viewHolder}">
<mx:SWFLoader id="movie" 
source="{'movies/'+_swf}" maintainAspectRatio="true" width="95%" 
height="95%" scaleContent="true" />
</mx:AddChild>
<mx:RemoveChild target="{thumbImage}" />
</mx:State>
</mx:states>

</mx:VBox>

 

Reply via email to