creation complete - apache-flex

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

Related

Spark Datagrid: issue with scrolling (selectionChange event)

I have a flex mobile project. In my homeview I have a spark datagrid. The selectionMode is "singleCell". I have an eventlistener on the datagrid which listens to the selectionChange event. When someone clicks on a cell, a callout view is showed with a list.
Now when I want to scroll in the datagrid (if it has many rows), obviously the selectionChange event is triggered instead of the normal scrolling. Does anyone has a solution for this?
The curious thing is, when you use a list (in place of a spark datagrid) with a change event (spark.components.supportClasses.ListBase.change), the list is able to say the difference between scrolling and a selection without any issue!
Correct, the issue is caused by the singleCell editmode #Al_Birdy.
I have semi-solved it by using a doubleclick event on the datagrid. The app will also be exported as a desktop application in the final stage so that isn't a real bad idea.
As www.Flextras.com pointed out, the datagrid is not yet optimized for mobile usage. If I may add something to that, it isn't that mature either. To solve this issue, basicly a likewise approach should be implemented like the list control has. In this control, this behaviour is implemented (the difference between a scroll event and a touch/click event). It kinda surprised me that the spark datagrid didn't had this behaviour. But then again it wouldn't surprise me they took the 'ol good desktop' component and ported it, which might explain everything.

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.

Decorating item renderers in custom list components

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?

destroy open item editor or item renderer in flex

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].

How to tell when an MXML component has totally finished creation?

An MXML component can be quite complex, containing many nested controls, including asynchronously loaded content such as Image/SWFLoader.
Is there one event I can watch for on my component that will only be raised when every control and sub-component has loaded, including SWFs and Images?
CreationComplete will NOT do the trick if you are talking about loading swf content or anything really external like that. CreationComplete gets fired when the MXML components have been laid out as defined in MXML (IE nested components, buttons, boxes, canvasses, etc.), so content that needs to get loaded externally (an image, a swf) does not count.
What you need to do is keep track of everything that you're waiting for and fire off a custom event once all of those elements have loaded.
One possible hackish way to do it would be to listen for whatever load complete event is relevant for each element, then have them call back to the same function that increments a value equal to the number of components you're waiting for. This means you have to pay more attention if you're modifying it, but it also means you don't have to check a boolean for every element that needs to load (IE "if (image1Loaded && image2Loaded && swfLoaded)" etc.)
The onApplicationComplete event?
The creationComplete event should do the trick - creationComplete is called on the parent component after it is called on the children.
You can get some more info on the component lifecycle in the Adobe docs.
In some complex cases, like when your component is considered "finished" only when some data has been retrieved via HTTP or something like that, custom event is your best bet.

Resources