Is it possible to destroy/close open item editor or item renderer of a datagrid in different mxml page?
I heard about the functions editedItemRenderer and destroyItemEditor on Datagrid. Can I use these functions in different mxml page?
Your question is a bit confusing.
Flex Applications do not have the concept of a page in the same way that HTML does. You probably mean different views, or MXML Components.
All itemEditors are created and destroyed as needed. If you are not viewing the itemEditor on screen, then likely something else has focus and the itemEditor was destroyed automatically.
In most cases, two components should not talk to each other using anything other than their defined API. so, you can have one component dispatch an event, then it's parent listen for the event and have that parent call methods on another component [such as a DataGrid].
Related
I'm building a Flex app that has to be accessible and meet section 508 guidelines. Some pre-built parts of are making heavy use of DataGroup, DataGrid, and ItemRenderers. I can't get anything that was created with ItemRenderers to even receive keyboard focus, so it seems impossible to have their accessibilityProperties revealed.
Is there a trick to making focus available to an ItemRenderer? Or some alternative I could use?
SOLUTION:
I kind of stumbled across this, and I'm not entirely sure why this works, but the solution is simple. Just add implements="mx.managers.IFocusManagerComponent" into the root tag of the custom ItemRenderer, and then each item in the list will be able to receive focus and expose its accessibilityProperties.
The strange is, the Flex compiler doesn't complain if the custom renderer fails to implement the required IFocusManagerComponent methods. I don't know why, but I would speculate that these methods are implemented somewhere up the code chain, and aren't used unless a component explicity implements IFocusManagerComponent.
The only problem I'm having now is that only the visible items show their accessibilityProperties, which makes sense because ItemRenderers are only created for the visible items on screen, but I should find some way to scroll the list automaticaly if the last visible ItemRenderer loses focus.
Has anyone had success creating a custom list component which accepts a user defined item renderer, but decorates it with another class to augment its behavior?
Examples of why this might be useful include:
catching and stopping the propagation of events or dispatching new events in place of others
incorporating behavior in the renderer to interface with other packages used by the custom component
adding expand and collapse buttons for resizing the internal renderer, etc
The idea here is to not require changing the users renderer to work with this component, so keep that in mind.
Yep, I did this with the Flextras DataSorter. The DataSorter is a customized list that acts like a Netflix Movie Queue. The user's itemRenderer contains their stuff, but our wrapper adds in the number input field, the move up button, the move down button, and the other button controls.
It is pretty much a nightmare that required a lot of heavy customization of the Flex List class.
Since you're question is a "Yes" or "No" question, I feel I've answered it. What else did you want to know?
Can i use creation complete in item renderers , i have a data grid and i have kept every single cell as an item renderer. is it a good practice to use creation complete here. I fear events might fire up at wrong instances.suggestions are most welcomed.
Use "dataChange" even instead.
More info at Adobe:
http://livedocs.adobe.com/flex/3/html/help.html?content=cellrenderer_7.html
Flex might reuse an instance of the
item renderer or item editor, a reused
instance of an item renderer or item
editor does not redispatch the
creationComplete event. Instead, you
can use the dataChange event with an
item renderer or item editor. Flex
dispatches the dataChange event every
time the data property changes.
The problem with item renderers is that their number depends on the visible area and they are reused in flex.Scrolling issues are a very common problem in datagrids using itemrenderer such as Checkbox,TextInput etc., due to this.So dont use event handler on creationComplete .
There is always a work around :)
creationComplete is a phase in the flex application life cycle.
For more information you can go through the following link:
http://technobytz.com/flex-preinitialize.html
I have a Flex application with three different views. Only one view is shown at a time, and the choice of view depends on what part of the application the user is working with. If it had been an ordinary HTML webapp I would have created three different HTML-templates/pages for each view.
What is the recommended way to handle such application views in Flex?
The behavior you want is usually accomplished by using a ViewStack component. In MXML you declare child containers for each view you want, but only one gets shown at a time. You can change which one is shown programmatically whenever conditions are met by setting selectedIndex on your ViewStack. By default the first child container is displayed when run. Another approach is to declare and use states in your container and change currentState whenever you need to change the view. Hope that helps.
I have two mxml files. one is main that is application tag mxml file and another is my mxml component file.
I have a viewstack in my main mxml whose id is, say, "mainViewStack".
Now I want to set selectedChild property of "mainViewStack" from my mxml component file.
But I m getting error:
Error #1009: Cannot access a property or method of a null object reference.
on accessing mainObj.mainViewStack.selectedChild.id where mainObj is the object of main mxml file.
Please help me out.
Thank u.
My guess is that you're trying to access the child before it's created. But that's hard to tell without the code.
Try waiting until the FlexEvent.CREATION_COMPLETE event on the application to access the selected child.
This issue is referred to as "deferred instantiation" and is a product of the Flex Component Lifecycle. If you want an extremely thorough explanation of this concept, this white paper is probably the best I have read.
Essentially Flex creates components as they are needed. Each component has a lifecycle that takes it through stages:
Construction
Addition
Initialization
Invalidation
Validation
Update
Removal
A sub-component isn't going to be accessible until it has passed through the initialization phase. This is the point at which a Flex component will dispatch its CREATION_COMPLETE event, letting you (and the framework) know that it is ready for interaction. Prior to this event, you are going to receive null reference errors when attempting to access the component or its children.
ViewStacks compound this by default by not initializing sub-components until they are called for display. The creationPolicy property of a ViewStack, by default, is set to auto. There are several options for this property, including all. Be aware, however, that this can potentially present severe performance issues, as all of the components inside the stack are going to be initialized immediately regardless of whether or not the user actually even looks at the component.
In your specific case this isn't the problem. The component that contains the view stack hasn't been completely initialized. You need to set the child of the ViewStack in a CREATION_COMPLETE event handler.
or you can give "creationPolicy=all" because Flex only creates the first visible child from the viewstack
You can use this code in your MXML component to change application's ViewStack selected child from other MXML component. However it is not a good practice.
FlexGlobals.topLevelApplication.mainViewStack.selectedChild = FlexGlobals.topLevelApplication.childId
You can use static event dispatcher to dispatch an event from one view and listen that event in an other view.