Dispatch event from itemrenderer

Greetings.
i've got a main applicationxml: main.mxml
followed by a component: optionbox.mxml, being loaded in the
main.mxml.
in optionbox.mxml another component is loaded:
optionCanvas.mxml
inhere, a datagrid is being created with a custom
itemrenderer: itemsRenderer.mxml
in this itemsRenderer (wich alters the display of the cells)
is an image located.
when you click this image, an object has to be dispatched to
the main.mxml.
how can I do this? It works when I dispatch from a component,
but not from an itemrenderer.
can anyone help me out.??
main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="vertical"
xmlns:c="comp.*"
backgroundAlpha="0"
backgroundColor="#FFFFFF">
<mx:«»Style>
global{
fontFamily:Arial;
Canvas{
color:#000000;
.FooterLink{
color:#0066CB;
fontWeight:Bold;
fontThickness:900;
.Footer{
backgroundColor:#E1F0F7;
DataGrid{
borderThickness:0;
selectionColor:#FFFFFF;
selectionDisabledColor:#FFFFFF;
disabledColor:#FFFFFF;
rollOverColor:#FFFFFF;
ToolTip {
fontFamily: Arial;
fontSize: 12;
color: #000000;
</mx:«»Style>
<mx:«»Script>
<![CDATA[
import events.itemEvent;
import mx.rpc.events.ResultEvent;
import mx.collections.ArrayCollection;
[Bindable]
private var selectedItems:ArrayCollection = new
ArrayCollection();
private function photoSelectedHandler(event:itemEvent):void{
selectedItems.addItem(event.selectedItem);
]]>
</mx:«»Script>
<mx:VBox width="980" height="100%">
<mx:HBox>
<mx:VBox>
<c:LeftPane id="leftpane" width="201" height="100%" />
<c:Checkout id="checkout" selectedItems="{selectedItems}"
styleName="checkout" fontWeight="bold"/>
</mx:VBox>
<c:«»Swfcontainer width="537"
height="405" />
<c:OptionBox width="222" height="100%" id="optionBox"
itemSelected="{photoSelectedHandler(event)}"/>
</mx:HBox>
<c:Footer width="100%"
styleName="Footer"></c:Footer>
</mx:VBox>
</mx:Application>
[/code:1]
optionbox.mxml
[code:1]<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="
http://www.adobe.com/2006/mxml"
color="#400000" creationComplete="printerData.send()"
xmlns:c="comp.*">
<mx:Metadata>
[Event(name="itemSelected",
type="events.itemEvent"«»)]
</mx:Metadata>
<mx:«»Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.collections.ArrayCollection;
[Bindable]
public var printer:ArrayCollection
private function printerDataHandler(event:ResultEvent):void{
printer = new ArrayCollection();
printer=event.result.printer.confItem;
]]>
</mx:«»Script>
<mx:HTTPService id="printerData" url="data/data.xml"
result="printerDataHandler(event)"/>
<mx:Accordion id="accOptions" width="100%" height="100%"
headerHeight="32" backgroundAlpha="0" fontSize="11" color="#0066CB"
resizeToContent="true">
<mx:Canvas label="{printer.getItemAt(0).label}"
width="100%" height="100%" backgroundAlpha="0">
<mx:VBox>
<mx:Text width="198"
htmlText="{printer.getItemAt(0).text}" />
</mx:VBox>
</mx:Canvas>
<mx:Repeater id="repAccOptions" dataProvider="{printer}"
startingIndex="1" >
<c:optionCanvas
itemData="{repAccOptions.currentItem}"/>
</mx:Repeater>
</mx:Accordion>
</mx:HBox>[/code:1]
optionCanvas.mxml
[code:1]<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="
http://www.adobe.com/2006/mxml"
label="{itemData.label}" width="100%" height="100%"
verticalScrollPolicy="off">
<mx:«»Script>
<![CDATA[
[Bindable]
public var itemData:Object;
]]>
</mx:«»Script>
<mx:VBox width="100%">
<mx:Text width="100%" htmlText="{itemData.text}" />
<mx:«»DataGrid
dataProvider="{itemData.consumables.consumable}"
headerHeight="0"
width="100%" itemRenderer="itemRenderers.OptionsRender"
alternatingItemColors="#FFFFFF">
<mx:columns>
<mx:«»DataGridColumn
dataField="consumableLabel" width="200"/>
</mx:columns>
</mx:«»DataGrid>
</mx:VBox>
</mx:Canvas>[/code:1]
optionsRenderer.mxml
[code:1]<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="
http://www.adobe.com/2006/mxml"
verticalScrollPolicy="off" horizontalScrollPolicy="off" width="165"
height="45">
<mx:Metadata>
[Event(name="itemSelected",
type="events.itemEvent"«»)]
</mx:Metadata>
<mx:«»Script>
<![CDATA[
import events.itemEvent;
[Bindable]
public var selectedItem:Object;
private function addItem(itemObj:Object):void{
selectedItem = new Object();
selectedItem = itemObj;
var eventObj:itemEvent = new
itemEvent(selectedItem,"itemSelected"«»);
dispatchEvent(eventObj);
]]>
</mx:«»Script>
<mx:Image source="assets/btnAddItem.jpg"
click="addItem(data)"/>
<mx:Text htmlText="{data.consumableLabel}"
height="45"/>
<mx:Image source="assets/btnInfoItem.jpg"
horizontalAlign="right">
<mx:toolTip>
{data.consumableLabel}
Partnumber:{data.consumablePartnr}
Price:{data.consumablePrice}
Omschrijving
{data.consumableDescr}</mx:toolTip>
</mx:Image>
</mx:HBox>[/code:1]

Override clone() method inside event to make sure you take into account the bubbling property, and then inside renderer dispatch the event with bubbling property set to true.
Alternatively you can dispatch on the list e.g :
owner.dispatchEvent(newCopyProductEvent(CopyProductEvent.COPY_PRODUCT,o));
If you choose to do the latter make sure you don;t get into an infinite loop inside list if you decide to redispatch from there,
C

Similar Messages

  • Dispatching event from Javascript

    Can I dispatch events from javascript to flash player? I am trying to do so by calling dispatchEvent() on flash player dom object but the event is not passing inside flash player. Any links or clue?

    To be specific ... I can catch a right click and supress it. But I want to send it to flash (lets say) as a left click. Problem is when i do that, javascript listner for dom element will get fired for left click but there wont be any events in flash.
    SO the question is can i fire events on flash from outseide or is it outside the public APIs?

  • Dispatch event from the main App file

    Hi,I have one simple question.I know how to dipatch events from the some of the components files to the main App file,but I don't know how to do the opposite?
    I have an HTTPService with id = "getData" in some component file and I want to dispatch an event that will send it getData.send();
    Is this possible,and it if is how?

    It is possible but not a recommended practice.
    Worst case you proxy out methods on your components and call directly:
    maiAPpp.someComponent.doSomething();
    SomeComponent
    doSomething();
        someOtherComponent.doSomething();
    SomeOtherComponent
    doSomething();
        servcie.send();
    My 2 cents are too look into MVC architecture and have the service inside a command which gets treiggered by a controlled which reacts to your event dispatched by the view.
    C

  • Dispatching event from skin

    Can I dispatch an event from the skin and have the hostcomponent listen it?  I have a text input and an info icon in frnt of it,  I want to show the tooltip of the textinput when there is a rollover event on the icon. I wrote a skin with the textinput and icon and in the rollover event on the icon I am dispatching an event and added an event listener to the hostcomponent of the skin. It seems like hostcomponent is not listening the event.
    My skin handles all the animation logic and contains the image and the textinput,and then I am extending the skinnable component class with the two skin parts and controlling the skin states from there. In the rollover event I dispatched an event which host omponent is supposed to catch and do the following:
    myTextInput. tooltip = _toolTip
    _toolTip is in the construcotr of the hostcomponent.
    What is wrong in what I did?  Why is my host component not receiving a event from the skin?

    Thanks for your reply. My code is kinda long and apparently I can't copy paste in this window(not sure why).
    Is there any way to attach the code somehow?

  • Dispatching events from JNI

    I've got an application that is trying to watch for mouse events anywhere and everywhere. The goal is to be in-the-know when there is mouse activity going on in general, with the Java app running in the taskbar.
    I have determined that I'll likely need JNI to accomplish this, as paying attention to mouse activity over the whole operating system is somewhat operating system dependent. : )
    Nevertheless, I'd like Java code to handle the events, and I can't seem to find any way for JNI to dispatch events back to the Java side of things. My hope was to catch the events thrown by the system in C/C++ and then simply dispatch them again to act as a middle-man.
    If anybody can tell me how I might accomplish this using JNI, or even a step in the right direction, I would greatly appreciate it. Or, if I'm barking up the wrong tree, please please let me know.
    Thanks,
    - J

    Steps in order
    1. Determine how to capture the events in C/C++. There is no java in this step.
    2. Write an API in C/C++ that models the functionality that you want to use in java. There is no java in this step.
    3. Write java/jni that uses the API in 2. There is java in this step.
    As a callback you will need to use the jni attach thread method.
    You better be careful as messing up on any of the steps above can render your mouse inoperable for the entire OS, so learn the keyboard shortcuts.
    I think that someone posted code like this in the past. I could be mistaken however.

  • Dispatching Event in ItemRenderer Component?

    Am I going about this the right way? Here's my situation:
    I have a custom itemRenderer for a List. This itemRenderer consists mainly of a checkbox and label, but has a few additional details in it (which is why I'm not using a drop-in itemRenderer). I want to detect when the selection of the checkbox changes, so I was thinking of creating a custom event in the itemRenderer and then bubbling it up to the list.
    Or is there a way I can detect when a user checks a checkbox from the lists itself?
    Thanks!

    I found this article which explains this topic very well also: http://weblogs.macromedia.com/pent/archives/2008/03/itemrenderers_p_2.html
    (It appears that these may be referencing the same series of articles on different sites.)
    However, I am now conflicted, because if I the version without bubbling, I am tying the itemRenderer directly to my component; whereas with bubbling I don't need to make that association. I may opt for the bubbling route after all, because I want to keep my itemRenderers generic enough to use in any of my custom controls, and not just in a certain type.
    For more clarification: the hangup is where the event gets triggered on the listData.owner. To do this, it appears that it must be type-cast first, and then manipulated. Any ideas on how to get around that? Here's Peter's example:
    ====================================
    First, you have to add metadata to the CatalogList control to let the compiler know the control dispatches the event:
         import events.BuyBookEvent;
         import mx.controls.TileList;
         [Event(name="buyBook",type="events.BuyBookEvent")]
         public class CatalogList extends TileList
    Second, add a function to CatalogList to dispatch the event. This function will be called by the itemRenderer instances:
              public function dispatchBuyEvent( item:Object ) : void
                   var event:BuyBookEvent = new BuyBookEvent();
                   event.bookData = item;
                   dispatchEvent( event );
    Third, change the Buy button code in the itemRenderer to invoke the function:
                   <mx:Button label="Buy" fillColors="[0x99ff99,0x99ff99]">
                        <mx:click>
                        <![CDATA[
                             (listData.owner as CatalogList).dispatchBuyEvent(data);
                        ]]>
                        </mx:click>
                   </mx:Button>
    Now the Button in the itemRenderer can simply invoke a function in the list control with the data for the record (or anything else that is appropriate for the action) and pass the responsibility of interfacing with the rest fo the application onto the list control.
    ====================================

  • Can you dispatch events from a custom component skin?

    If so, how?
    Thanks~Benny

    I'm curious to know if this is possible as well (or really the question should be, is there a non-hackish way to get a reference to the skin instance)?
    When I've needed to do something like this, I've always just dispatched an event off a skin part from within my skin. IE.
    this.contentGroup.dispatchEvent(...)
    Then I would just listen for the event on the skin part.
    This is a bit hackish, so it would be nice if someone could share a better solution. I've been meaning to look into it, just never have been able to justify the time looking for a better solution.

  • How to dispatch events from custom AS3 classes to MXML

    Hello,
    I introduce some custom classes inside my SCRIPT tag in MXML.
    These classes should dispatch custom Events (or any events for that
    matter) and the listeners should be defined inside the SCRIPT tag.
    In the custom class I have:
    quote:
    dispatchEvent(new Event("customEvent"));
    And inside the script tag:
    quote:
    addEventListener("customEvent", testListener);
    quote:
    public function testListener(evt:Event):void{
    Alert("Event fired successfully.");
    However, this event is not handled in the listener (the alert
    is not shown). What could be wrong?

    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute" creationComplete="init();">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    private function init():void
    addEventListener("customEvent", testListener);
    dispatchEvent(new Event("customEvent"));
    private function testListener(evt:Event):void{
    Alert.show("Event fired successfully.");
    Do like this
    Alert is the Class Object. This is not the Function.

  • Help dispatching events from glassPane to other components

    Hi guys,
    I laready did a search in the forum but everybody seems to have trouble blocking events via GlassPane.
    For me it is the opposite.
    I set a glassPane on the Frame via setGlassPane()... works great but now i can't dispatch the events to the rest of the UI. Can someone please give me some example code how to do that;
    Here is what i have tried :
    myFrame.this.getGlassPane().addMouseListener(new MouseAdapter()
    public void mouseClicked(MouseEvent e)
    Frame.this.getRootPane().dispatchEvent(e);
    public void mousePressed(MouseEvent e)
    Frame.this.getRootPane().dispatchEvent(e);
    public void mouseReleased(MouseEvent e)
    Frame.this.getRootPane().dispatchEvent(e);
    public void mouseEntered(MouseEvent e)
    Frame.this.getRootPane().dispatchEvent(e);
    public void mouseExited(MouseEvent e)
    Frame.this.getRootPane().dispatchEvent(e);
    Please show how it is done ...

    Hey Tom,
    You know what's funny, i read that article already and even look at the code but it was too complicated for me...And now that you mentionned it again i decided to look at it again and took one method out of it and now it seems to work but i still don't quiet understand what it does exactly??? Thanks For pushing My Back :)
    Any Other way to do that ???
    private void redispatchMouseEvent(MouseEvent e)
    Point glassPanePoint = e.getPoint();
    Container container = this.getContentPane();
    Point containerPoint = SwingUtilities.convertPoint(this.getGlassPane(), glassPanePoint,container);
    //The mouse event is probably over the content pane.
    //Find out exactly which component it's over.
    Component component =
    SwingUtilities.getDeepestComponentAt(
    container,
    containerPoint.x,
    containerPoint.y);
    if ((component != null) )
    //Forward events over the check box.
    Point componentPoint = SwingUtilities.convertPoint(
    this.getGlassPane(),
    glassPanePoint,
    component);
    component.dispatchEvent(new MouseEvent(component,
    e.getID(),
    e.getWhen(),
    e.getModifiers(),
    componentPoint.x,
    componentPoint.y,
    e.getClickCount(),
    e.isPopupTrigger()));

  • Dispatchig event from one module and listen it in an other module

    Hi,
    I would like to know if it's possible to dispatch event from module for example "M1" and listen this event to call the corresponding command but in an other module "M2". Knowing that M1 produces an swf "SWF1" and M2 produces an other swf "SWF2". For example :
    In the view of a module M1, I should have this statement : CairngormEventDispatcher.getInstance().dispatchEvent(new MyClassEvent(parm));
    know in module "M2" I would like to know how to recover this event and then executing command corresponding to this event.
    If it's not clear enough I can explain it again.
    I need really your help for the rest of my development.
    Thank you in advance. :)
    Ziad.

    Hi Ziad,
    Sorry, but this forum is for discussing the future of cairngorm, not how to use it today.
    I suggest you post your question on the FlexCoders mailing list or on the Cairngorm Documentation Group :
    http://tech.groups.yahoo.com/group/cairngorm-documentation/
    Thanks ;)

  • Dispatch custom event from itemClick handler

    hi,
    I'm trying to dispatch a custom event from my itemClick handler.
    So when I click on an item of my datagrid, I want to send a custom event.
    private function dataGridItemClickHandler( event:ListEvent): void
         dispatchEvent( new myEvent( myEvent.NEW, values[event.columnIndex]["name"]) );
    <mx:DataGrid dataProvider="{values}" itemClick="dataGridItemClickHandler(event)">
    </mx:DataGrid>
    but this code doesn't work.
    Can you help me
    thanks
    best regards

    Please see that you override the function clone() and return the new function.If that is correct.you can call the super() method to initialize your base class.
    If your custom event {myEvent} is in package say: CustomEvent,
    1)import package CustomEvent.myEvent
    2) keep in <mx:metadata>[Event(name="NEW", type="CustomEvent.myEvent")]</mx:metadata>.. name suggest  what type of event you want
    3)Create an itemclick listener and in dataGridItemClickHandler
    private function dataGridItemClickHandler( event:ListEvent): void
         dispatchEvent( new myEvent( ' NEW ', values[event.columnIndex]["name"]) );
    private funcation myEventListener(evt:myEvent):void
    //Put your logic
    4)Use this event by name NEW="myEventListener(event)"  this will behave as event type in the datagrid tag like click, hover and others.
    Hope this helps! Please excuse if anything is logically incorrect.Do point out.Thanks.

  • [svn:osmf:] 14474: Adding a 'dispatchInitialChangeEvent' parameter to the ' watch' method in order to allow the initial change event from being dispatched, continued.

    Revision: 14474
    Revision: 14474
    Author:   [email protected]
    Date:     2010-02-28 23:53:31 -0800 (Sun, 28 Feb 2010)
    Log Message:
    Adding a 'dispatchInitialChangeEvent' parameter to the 'watch' method in order to allow the initial change event from being dispatched, continued.
    Modified Paths:
        osmf/trunk/framework/OSMF/org/osmf/metadata/MetadataWatcher.as

    *Feedback*
    "Use the form below to send us your comments. We read all feedback carefully, but please note that we cannot respond to the comments you submit."
    http://www.apple.com/feedback/ipad.html
    We can complain about Apple's business decisions, but these discussions are user to user talk about possible solutions.
    Here are the places to report bugs:
    Get an account at
    http://developer.apple.com/  then submit a bug report to http://bugreporter.apple.com/
    Once on the bugreporter page,
       -- click on New icon
       -- See if you need to attach a log file or log files, clicking on Show instructions for gathering logs.  Scroll down to find the area or application that matches the problem.
       -- etc.

  • [svn:osmf:] 14473: Adding a 'dispatchInitialChangeEvent' parameter to the ' watch' method in order to allow the initial change event from being dispatched.

    Revision: 14473
    Revision: 14473
    Author:   [email protected]
    Date:     2010-02-28 23:45:28 -0800 (Sun, 28 Feb 2010)
    Log Message:
    Adding a 'dispatchInitialChangeEvent' parameter to the 'watch' method in order to allow the initial change event from being dispatched.
    Modified Paths:
        osmf/trunk/framework/OSMF/org/osmf/metadata/MetadataWatcher.as

    Perhaps you're not handling the "EndOfStreamEvent" correctly/at all, and thus not freeing up the socket to listen for the "NewReceiveStreamEvent " after the initial stream has ended...
    ?

  • Dispatching an event from a command

    Hi,
    In one for my commands in the Cairngorm based application I'm working on I need to dispatch a event to amend the view. In my command I'm amending some value objects in a ArrayCollection, which is the data source for a List component in my view. Once I completed my changes to these value objects I'd like to dispatch a event to resort the ArrayCollection and update my view to the new order.
    What is the best approach for dispatching an event in the command?
    Thanks
    Stephen

    Great question - I'm currently sorting out how to do this myself.  I'm new to Cairngorm but have a decent amount of experience with Flex.  Here are my thoughts:
    Cairngorm promotes decoupling of the data model and front controller/commands from the view - which is appropriate for an MVC framework. Data binding supports this seperation (to an extent) and keeps the view up to date with the model in 'real time'.  Data binding does not however provide an intuitive mechanism for reacting to cairngorm event results.  So here a few solutions I've been tossing around:
    1.  Rely on Built in Flex events such as the datagrid's dataChange event to trigger a reaction.
    2.  Create view state variables in the model that, when changed through the front controller / commands, dispatch custom events from within their VO's / setters / ect.
    3.  Dispatch custom events directly from front controller / commands.
    4.  Create custom (or override existing) item renderers that self-transition / tween when changed as a result of data binding.
    I'm sure there are other ways to do what we want, but I'm out of ideas.  Which approach to take very well depends on how strongly you'd like to adhere to the MVC concept.  Commands that dispatch generic events as their messages may or may not be acceptable to you - but they provide a straitforward way to trigger view related reactions without relying on data binding events.  I'd be interested to know if Cairngorm 3 will address this challenge...
    Let me know what you decide on if and when you make a choice!

  • Dispatching an event from a MovieClip???

    Hello, can somebody tell me if there is a way to dispatch an
    event from a Movieclip?, I tried to dispatch an event from a class
    and all ran ok. But now, if I have a Movieclip on my scenario and I
    want that when it arrive to "x" frame it dispatch an event that
    could be catched by a listener on the _root, what I have to do?
    (without doing use of classes), thanks a lot.

    Try the following. On the first frame of the movieclip place
    the following code.
    // Event Routines //
    var dispatchEvent:Function;
    var addEventListener:Function;
    var removeEventListener:Function;
    mx.events.EventDispatcher.initialize(this);
    Then on the "x" frame of the movieclip, place the following
    code:
    var evt:Object = new Object();
    evt.type = "framereached"; // this can be whatever you wish
    to listen for
    evt.target = this;
    dispatchEvent(evt);
    This is how you would do this in a class and it should work
    just as well if coded directly onto a frame. However, to make this
    more versatile I would place it in a class with a public function,
    for example, name throwEvent(). This public method would then
    execute the above code and could be called from any frame. You
    could even add another item to the evt object that would contain
    the frame the executed the event.
    Tim

Maybe you are looking for

  • How to get User input in JTextField?

    How to get User input in JTextField? Can u anyone give me some code samples? thanks

  • Unable to activate Volume Icon on DV7/ Win 7.1

    DV7 on Win 7.1 All other system icons can be turned ON or OFF with exception of Volume. An attempt to Customize the Taskbar shows IDT PC AUDIO (to control Beats Audio) whose Icon can be added to the taskbar

  • Shot matcher with multiple video tracks and clips bug

    Hello again, Very problematic bug : at least in direct link mode, when using shot matcher, if the shot to be matched is on top of other clips below, then it produces odd results. In a word, it doesn't work. Can't think of a workaround or another work

  • Question about working with an audio interface

    Hi I just bought an audio interface (tascam us-122l) and i have logic express 8 installed, so i've connected my guitar and my keyboard (via MIDI) to the audio interface, and i've read the user's manual but i still don't know how things work... Is it

  • Ios 6.1.2

    Trouble with new IOS 6.2.1!!! HUGE crash with most of my apps but on top of this... No more music if i don't have head set on the iphone. The slide bar for volume is gone ???? How can i get back to IOS 6.1.1 or 6.0.1