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.
Related
I would like to bind two components with out binding and which resides in different MXML.
for eg: A.mxml has textinput and B.mxml has a combobox when choose one item in B.mxml selected item should be display in A.mxml textinput.
Listen for the Combobox's change event and in the event handler update the text property of your text input. As you have mentioned that both reside in separate mxml's, you might need to add eventlistener on (common) parent to both.
"Flex in a week" on day 3 of traing has some good information on extending the event class.
http://www.adobe.com/devnet/flex/videotraining.html
Extending the event class for the "change" event would be an easy way to handle this.
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"/>
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.
In short:
I need an event listener in a custom component so all its instances (without editing them) react at the same time, fired by a dispatched event in its parent container.
In detail:
I have a custom component with Tab navigator. (The tabs are intended to show different preferences for different Languages.)
I have a button bar with buttons for all the languages.
There are a lot of instances of the custom component.
I want to click in a button of the languages bar and get ALL the instances switched to the same tab (the custom component contains the logic to change the tab).
I can do it by adding the event listener for EACH INSTANCE of the custom component, so it calls an internal function that changes the tab. But it seems to be very coupled, isn't it?
I wonder if it can be done in the master CLASS of the component, so it listen for events in its parent container, whichever it is.
In my mind this code shoud work, but it doesn´t (obviously ill'use a custom event to pass the new language value):
this.parent.addEventListener("lang_change", this.change_tab);
This way I can just drop an instance of the component, and see it working for itself.
Thank you in advance
I need an event listener in a custom
component so all its instances
(without editing them) react at the
same time, fired by a dispatched event
in its parent container.
The very thing you want to do, by definition, breaks encapsulation. In an ideal world, a component should know nothing of it's parent. If the component needs to communicate with it's parent, it should dispatch an event. IF a parent needs to communicate to children it should call a public method on that child (or change a public property). From an encapsulation stand point, I cannot recommend that the child listen for events on the parent.
I want to click in a button of the
languages bar and get ALL the
instances switched to the same tab
(the custom component contains the
logic to change the tab).
So, then put a click handler for the button and do something like this:
public function onClick():void{
myCustomTabNavigator1.selectedIndex = 1
myCustomTabNavigator2.selectedIndex = 1
myCustomTabNavigator2.selectedIndex = 1
}
You can also set the selectedItem if you a reference to it. , If you have your custom TabNavigators in an Array, you can loop over them. IF the custom TabNavigators are child of your custom component you can create a method in that custom component to set the defaults and call that method on each component instead of setting selectedIndex directly.
I think you should to use some MVC model like:
Cairngorm
http://code.google.com/p/swizframework/
http://www.robotlegs.org/
http://puremvc.org/
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