I have a mediated view with a DataGroup with a custom ItemRenderer. I want when I click a button in the ItemRenderer to dispatch a signal and handle it in my mediator? How can I do that?
Thanks in advance
In your item renderer dispatch an event that bubbles, then on your DataGroup add a listener for that event (in your mediator).
Related
I want do to the next one in flash with ActionScript 3.0:
Global event (if user click in any part of the screen by mouse):
addEventListener (MouseEvent.CLICK, nextc);
function nextc (event:MouseEvent): void
{nextFrame();}
Button event (if user click exact this button):
returnb54.addEventListener(MouseEvent.CLICK, returnb54a);
function returnb54a(event:MouseEvent):void
{prevFrame();}
But on the frame with this a global event and a button nothing happens when clicking the button.
Is there any way to prioritize button event over global?
Thank you.
I created a very simple application to test your question (I'm using the same names as you defined, to be easier to understand).
I have changed 3 points:
1-
this.stage.addEventListener (MouseEvent.CLICK, nextc);
2-
function returnb54a(event:MouseEvent):void
{
event.stopImmediatePropagation();
prevFrame();
}
3-
function nextc(event:MouseEvent): void
{
event.stopImmediatePropagation();
nextFrame();
}
The method: stopImmediatePropagation() prevents processing of any event listeners in the current node and any subsequent nodes in the event flow. This method takes effect immediately, and it affects event listeners in the current node. In contrast, the stopPropagation() method doesn't take effect until all the event listeners in the current node finish processing.
Try to implement these changes and see if will have the desired result.
I have a case where the SelectedItem isn't called after the data provider changes for
a dropdownlist.
is there a way to detect if such a change occurred?
Thanks
Just about every public property in the Flex Framework has a 'propertyChanged' event that is dispatched from the properties set method. They are used primarily for binding purposes, but not usually formally documented.
The dataProvider set method of a DropDownList does indeed dispatch a dataProviderChanged event. The code is several layers up in the hierarchy, as part of SkinnableDataContainer or if the skin for your 'SkinnableDataContainer' has a dataGroup it is dispatched from the DataGroup.
But, this event will probably will not be exposed via code hinting in MXML. You'll have to listen for it in ActionScript:
myList.addEventListener('dataProviderChanged', onDataProviderChanged);
Keep in mind this event will always be dispatched when the dataProvider changes, regardless of what happens to the selectedItem property.
You can listen to changes in the selectedItem in a DropDownList through the IndexChangeEvent, illustrated by the code below:
<s:DropDownList id="dl_mydl"
dataProvider="{dataProvider}"
change="dropDownListChangeHandler(event)"
/>
protected function dropDownListChangeHandler(event:IndexChangeEvent) : void
{
//DO SOMETHING
}
How do you bind an event listener from the controller to the view's elements eg button (click event) to its own handler?
Originally I was doing this from the view eg.
button.addEventListener(MouseEvent.CLICK, controller.buttonClick);
But now realise this is wrong since reading "each view is only supposed to "know" about the model which it represents, and "know" nothing of the controller"
model should have instance of this button, so controller will access model to add event listener, but view will only show this button, only add to stage.
Controller has direct reference to the view so can bind event listeners to the appropriate view elements. View can expose public methods to set bindings if you like.
I have a itemrenderer in datagrid and I am trying to get the instance of itemrender in datagrid keypressevent as follows
var col:DataGridColumn = _datagrid.columns[_datagrid.selectedCells[0].columnIndex];
var myItemrend:MyItemrender = col.itemRenderer as MyItemrender;
But the above myItemrend instance is null. How can I get the itemrenderer instance.
Please help.
Thanks,
Rejeev.
I have an itemrenderer in Datagrid and it is used as itemeditor also by rendererIsEditor=true. My itemrenderer has a textinput and a list, where I open the list, for editing, when a focusin event is occurred in textinput, this happens while clicking the cell.
I need the same editing to happen while I enter using the keyboard(Enter), so I am trying to get the instance of the itemrender in Keyboard.ENTER and using this I can dispatch the textinput focusin event.
Thanks,
Rejeev.
Is it possible to dispatch an event from an object when an event listener is added to that same object, without overriding the addEventListener method of that class?
I am working on a modularized application in AS3. Several of the modules register events on a component in the main application mxml file. I would like to fire an event anytime an event is registered to the component from any module, without putting "dispatchEvent(someEvent)" after every addEventListener.
Any input would be greatly appreciated?
I don't know of any built-in that will help you, but you could just write your own function to encapsulate those.
public static function addEvent(ed:IEventDispatcher, evt:String, handler:Function) {
ed.addEventListener(evt, handler, false, 0, true);
ed.dispatchEvent(new Event("addedEvent"));
}