PDA

View Full Version : How to access a component in an itemrenderer ?


circass
08-25-2010, 08:40 AM
Hello,
i am trying to write something like image gallery.
I create a layout system by using that kind of code :


<s:Scroller width="100%" height="100%" id="gridContainer">
<s:DataGroup width="100%" id="gridDeneme">
<s:itemRenderer>
<mx:Component>
<s:ItemRenderer>
<ns1:ImageViewer imageURL="{data.imageUrl}"
id="imageViewer"
bitmapScaleFactorMax="5"
bitmapScaleFactorMin=".05"
width="{data.width}" height="{data.height}"
x="0" y="0"/>
</s:ItemRenderer>
</mx:Component>
</s:itemRenderer>
<s:layout>
<s:TileLayout />
</s:layout>
</s:DataGroup>
</s:Scroller>

I am using adobe imageviewer component with some changes and i want to use its functions, so i have to access the imageViewer which is inside that:

<s:itemRenderer>
<mx:Component>
<s:ItemRenderer>
<ns1:ImageViewer imageURL="{data.imageUrl}"
id="imageViewer"
bitmapScaleFactorMax="5"
bitmapScaleFactorMin=".05"
width="{data.width}" height="{data.height}"
x="0" y="0"/>
</s:ItemRenderer>
</mx:Component>
<s:itemRenderer>

how can i get those imageViewers in runtime ?

for(var i:int = 0; i< gridDeneme.numChildren;i++)
{
gridDeneme.getChildAt(i).filters = null;
}

I am accessing childs of gridDeneme Datagruop but when i want to cast them to imageViewer it returns me null... I dont know what else i can do...
Thank you
Regards.

circass
08-25-2010, 08:49 AM
Ok i found the solution of my problem...

for(var i:int = 0; i< gridDeneme.numChildren;i++)
{
gridDeneme.getChildAt(i).filters = null;
var ali:ItemRenderer = gridDeneme.getChildAt(i) as ItemRenderer;
for(var j:int = 0; j< ali.numChildren;j++)
{
var veli:ImageViewer = ali.getChildAt(j) as ImageViewer;
veli.zoom("in");
}
}
with that i can access my viewers...

hellix
08-26-2010, 07:16 PM
Hi.

You can also to add eventlistener to Spark DataGroup:

<s:DataGroup itemRenderer="dgControls.DgControlRenderer"
rendererAdd="onRendererAdd(event)">
<fx:Script>
<![CDATA[
import spark.events.RendererExistenceEvent;
private var _itemRenderers:Array = [];

/**
* Array of itemrenderers
* */
public function get itemRenderers():Array
{
return _itemRenderers;
}

/**
* Add renderer to array
* */
protected function onRendererAdd(event:RendererExistenceEvent):void
{
_itemRenderers.push(event.renderer);
}
]]>
</fx:Script>
</s:DataGroup>


My itemrenderer is stored in another file. Everytime when instance of item renderer is created in method onRendererAdd i add this instance to array.

ItemRenderer display properties from vo PersonVo:


public dynamic class PersonVo
{
public var firstName:String;
public var surname:String;

public function PersonVo(firstName:String = null,
surname:String = null)
{
this.firstName = firstName;
this.surname =surname;
}
}



<s:ItemRenderer autoDrawBackground="true">
<s:HGroup gap="5"
height="100%">
<s:Label id="firstName"
text="{data.firstName}"/>
<s:Label id="surname"
text="{data.surname}"/>
</s:HGroup>
</s:ItemRenderer>


Access to item renderer is clear and simple:


var count:int = dg.itemRenderers.length;

for(var i:int = 0; i < count; i++)
{
var dgRenderer:DgControlRenderer = dg.itemRenderers[i];
dgRenderer.firstName.text = "Ola";
dgRenderer.surname.text = "O.";
}

---
Greetings