Flex Hero spark component - changing view from within custom itemrenderer - apache-flex

I've made a custom list itemRenderer with 2 buttons and a label. One button deletes the list entry (and thats not the problem) the second button would change the actual view.
Does anyone knows how I can change actual view within the itemrenderer ?

From what I think I understand, you want to change a viewstack or something. What you want to do is bubble an event from the itemRenderer up to a point in the display list where someone will listen and trigger an event handler which then changes the view.
So, in your itemRenderer do
dispatchEvent(new Event('someEventName', true));
And up the display list you need to listen for that even
this.addEventListener('someEventName', someHandlerFunction);
And in that function just switch your view or whatever else you want.

Related

Flex 4.5: Custom component doesn't get visible in custom ItemRenderer

I'm developing a dynamic ItemRenderer to edition in line for Spark DataGrid.
With the Click event on Edit button (first column), I'm refreshing the cell's row using grid.invalidateCell(x,y); inside this custom ItemRenderer, in the function prepare, I'm evaluating an 'editing' dynamic property to hide/show (.visible/.includeInLayout) the default Label or Control for edition; I'm not using actually the itemEditor DataGrid's operation, just simulating this functionality.
Everything goes well with standard spark components for edition: TextInput, ComboBox, etc, but custom components (extended from SkinnableContainer) doesn't get visible, just randomically on first row sometimes.
Is there any specific interface that custom components must implement to work inside an ItemRenderer??
The problem was this property: customComponent.includeInLayout; once you set it to false, it has problems to get visible again. I think it's bad idea to use includeInLayout inside an ItemRenderer.
Now I'm working only with .visible=(false/true) and .x coordinate.
Thanks.

Flex 4.6 Mobile - how to know which itemrenderer is visible

I have a sparks List with the following attributes:
verticalScrollPolicy="off"
horizontalScrollPolicy="on"
pageScrollingEnabled="true"
scrollSnappingMode="leadingEdge"
and inside is an ItemRenderer that takes up a full screen for each item. So basically it is a horizontal list that lets you swipe left and right one page at a time. Note the scrollSnappingMode is on, so the pages always snap perfectly on the page.
Also, I am setting "useVirtualLayout=true" on the Layout, so I have virtual ItemRenderers that are getting recycled.
My question is this: how do I know which ItemRenderer is currently on the screen? Is there an event or property to watch that lets me know when this page has snapped into view and is the currently visible page?
how do I know which ItemRenderer is currently on the screen?
In the situation you describe, which uses Virtual Layouts and only one element displayed on screen at a time; there will only be a single itemRenderer.
You can access the dataProvider element of the itemRenderer using the data property on your itemRenderer.
You can find the index of your data in the dataProvider using the itemIndex property on the itemRenderer.
If you want to know when the list changes from the component that contains the list; you may try listening to the change event; but I'm not sure if that will give you want you need; as it is possible to scroll without selecting a new item.

Adobe Flex reference another object

I have a flex 3 datagrid that is in a completely separate container from the object that I am trying to reference it from - i.e. the datagrid is in a vbox, and I am trying to set a property in the datagrid from a popup.
How do I access the datagrid from the popup?
I'd like to do something like:
myView.myDatagrid.resizableColumns = false;
Using cairngorm as a framework if that is of any help.
You'll have to explain your architecture better to get a specific answer. This answer may help as everything I said about running methods on another component, also applies to accessing properties.
One solution for you is to pass the DataGrid instance into the popup as an instance variable; then the PopUp will be able to change the DataGrid's properties easy.
When you add your popup, you need to listen for an event. Then your PopUp needs to dispatch an event that the parent can handle.
myPopup.addEventListener(SomeEvent.DISABLE_COLUMNS,disableResize);
and then in the parent component
public function disableResize(event:SomeEvent):void{
myDatagrid.resizableColumns = false;
}
This assumes a custom event called SomeEvent... you can actually just create a default Flash event and give it a name like
dispatchEvent(new Event("MyDisableResizeEvent"));
Assuming you've got a button in your popup:
<mx:Button click="{dispatchEvent(new Event('MyDisableResizeEvent'));}" label="Disable Resizing"/>

How to pass events between an Itemrenderer and its parent

I have a spark list control whose data is rendered using an itemrenderer. Basically the Item renderer lays out the data within a Panel.
The Panel has a LinkButton, which when clicked needs to pass an Id to the parent application. In the parent application I have a function that dispatches a custom event to its parent. I want to know how to call this function from the ItemRenderer.
I tried using parentDocument.outerfunction etc but it throws an error..
Any clues ?
I would have your item renderer dispatch a custom event that contains your Id, making sure that your event bubbles. Then in the parent application listen for that event and call the appropriate function. Hope that helps.
If I understand well you can try to call from the item renderer this.parentApplication or this.parent.parent.
The best way is to create a custom event and bubble .. and add an event listener for that event in parent document..
this is working I have test parentcomponent(this.owner.parent).function...owner is list and parent is the component in which list is placed e-g InvitationList(this.owner.parent).invitationAccepted(persist);
type cast the this.owner.parent to your parentclass
If you were using PureMVC, you could send a notification that the receiver would handle and perform the needed work. This is similar to firing a custom event and receiving it in the parent.

how to loop over a datagrids rows in flex

I have a DataGrid which contains a DataGridColumn with a textinput and DataGridColumn with a Button.
The DataGrid is bound to some XML which displays values in the text box.
When the button for a row is clicked I need to get the value out of the text box and save it into the relevant XML node.
My solution was just to pass the id of the row to the button click event then loop over the rows until I find the id then just grab the text box value. Simple.
However the only advice I can find on looping over the rows is via the underlying dataProvider, which is nonsense as the two aren't the same thing.
Is this even possible? or is there a better way?
NOTE I would prefer not re-writing the markup, unless I have to.
Thanks
You are probably using an itemRenderer for your DataGridColumn to show the textBox (aka, TextInput component). I suggest that you dispatch a custom event out of the TextInput itemRenderer when you have a TextInput.dataChange event (or some other TextInput.Event that suits when you are ready to save the value).
http://livedocs.adobe.com/flex/3/langref/mx/controls/TextInput.html
Please remember that you need to bubble this event handling outside of the itemRenderer (e.g., the DataGrid) -- itemRenderers don't handle events well.
Also, one reason that a button to save your TextInput value is not a good idea, is because they are both itemRenderers, and it is hard to communicate between itemRenderers -- it is hard because Adobe deems it unclean code.
http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html
Also, this is another solution that changes the dataProvider for a ComboBox (in your case, it's a TextInput instead of ComboBox):
http://www.switchonthecode.com/tutorials/simple-datagrid-item-editor-in-flex
listData.rowIndex from the itemRenderer returns the current row index. You can read it from the click handler as:
private function clickHandler(event:MouseEvent):void
{
var listData:BaseListData = IDropInListItemRenderer(event.target).listData;
var clickedRowIndex:Number = listData.rowIndex;
}

Resources