Dispatching & listening for custom events from custom component [Flex 4.1]

I'm giving this a try for the first time and I'm not sure I have the recipe correct!
I have a custom component - it contains a data grid where I want to double click a row and dispatch an event that a row has been chosen.
I created a custom event
package oss
    import flash.events.Event;
    public class PersonChosenEvent extends Event
        public function PersonChosenEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
            super(type, bubbles, cancelable);
        // Define static constant.
        public static const PERSON_CHOSEN:String = "personChosen";
        // Define a public variable to hold the state of the enable property.
        public var isEnabled:Boolean;
        // Override the inherited clone() method.
        override public function clone():Event {
            return new PersonChosenEvent(type);
Then I try to dispatch the event within the component when the datagrid is doubleclicked:
import oss.PersonChosenEvent
dispatchEvent(new PersonChosenEvent(PersonChosenEvent.PERSON_CHOSEN, true, false));
And in the parent application containing the component I do on creationComplete
addEventListener(PersonChosenEvent.PERSON_CHOSEN,addPersonToList);
The event does not seem to fire though. And if I try to evaluate the "new PersonChosenEvent(..." code it tells me "no such variable".
What am I doing wrong?
(It was so easy in VisualAge for Java, what have we done in the last 10 years?? )
Martin

I've done this kind of thing routinely, when I want to add information to the event.  I never code the "clone" method at all.
Be sure that you are listening to the event on a parent of the dispatching component.
You can also have the dispatching component listen for the event too, and use trace() to get a debug message.
I doubt if it has anything to to with "bubbles" since the default is true.
Sample code
In a child (BorderContainer)
dispatchEvent(new ActivationEvent(ActivationEvent.CREATION_COMPLETE,null,window));
In the container parent (BorderContainer)
activation.addEventListener(ActivationEvent.CREATION_COMPLETE,activationEvent);
package components.events
    import components.containers.SemanticWindow;
    import components.triples.SemanticActivation;
    import flash.events.Event;
    public class ActivationEvent extends Event
        public static const LOADED:String = "ActivationEvent: loaded";
        public static const CREATION_COMPLETE:String = "ActivationEvent: creation complete";
        public static const RELOADED:String = "ActivationEvent: reloaded";
        public static const LEFT_SIDE:String = "ActivationEvent: left side";
        public static const RIGHT_SIDE:String = "ActivationEvent: right side";
        private var _activation:SemanticActivation;
        private var _window:SemanticWindow;
        public function ActivationEvent(type:String, activation:SemanticActivation, window:SemanticWindow)
            super(type);
            _activation = activation;
            _window = window
        public function get activation():SemanticActivation {
            return _activation;
        public function get window():SemanticWindow{
            return _window;

Similar Messages

  • Listening for keyPressed events from background?

    Is it possible to have a java program running in the background and listen for keyPressed events? I would like for the program to listen for certain keys to be pressed and when they are manipulate the mouse. From what I've looked at so far however it seems the listening component must have focus. Thanks.

    On any OS that would typically involve hooking into the OS itself.
    And then manipulating OS resources as well.
    Putting an app into the 'background' is also OS specific.
    Given that the above is all you want to do then java is not an appropriate language choice. C++ would be better.

  • Component listening for a event

    I need to make 1 component listen for an event in another component..
    JMenuItem listens for a TreeSelectionEvent and in case something selected enables... and disables otherwise...
    addTreeSelectionListener() is not possible for a JMenuItem component...
    so how do i do that?
    the code below is not acceptable because there is a lot of JMenuItem objects and it's a bit messy and difficult to add each...
    tree.addTreeSelectionListener(blah) {
    JMenuItem.setEnabled(false);
    i want a component checking himself for a proper condition...
    in case it will require too much hardware resourses what would you suggest?

    Do you ever get to a point in programming where you think that perhaps i have choosen the wrong hobby to get infatuated about
    That code worked really well targetplanet but it had a side effect that just makes me nutts lol
      as it triggered a mouse event function in the component that was initialized in Main and just made my web site go nuts . the component that we initialized was a skin but its itemRenderer component that followed had the mouse event! perhaps i better start again with me learning perhaps i missed something
    or perhaps i should just have one component to one job instead of trying to be clever and mutitask with less components!

  • Listening for click event

    I am curious, how can you have a child mxml page listen for
    an event from the parent?
    Let's say you have a button, call it 'btn1' on page1.mxml and
    you want to listen for the click event on page2.mxml. So far this
    is what I have:
    page1.mxml:
    <mx:Button id="btn1" />
    page2.mxml:
    <mx:Script>
    <![CDATA[
    private function btnListener(e:MouseEvent){
    Application.application.btn.addEventListener(MouseEvent.CLICK,
    setState(1));
    ]]>
    </mx:Script>

    "spacehog" <[email protected]> wrote in
    message
    news:glljts$g04$[email protected]..
    >I am curious, how can you have a child mxml page listen
    for an event from
    >the
    > parent?
    >
    > Let's say you have a button, call it 'btn1' on
    page1.mxml and you want to
    > listen for the click event on page2.mxml. So far this is
    what I have:
    >
    > page1.mxml:
    >
    > <mx:Button id="btn1" />
    >
    > page2.mxml:
    >
    > <mx:Script>
    > <![CDATA[
    >
    >
    > private function btnListener(e:MouseEvent){
    >
    Application.application.btn.addEventListener(MouseEvent.CLICK,
    > setState(1));
    > }
    > ]]>
    > </mx:Script>
    Check out Q3:
    http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf

  • Listening to event from custom component

    I have a main.mxml file, and 2 custom components: component1.mxml and component2.mxml
    I want to dispatch an event from component1 and handle it in component 2.
    I'm able to do this by handling the event first in the main.mxml then passing it on.
    But is there a way not to involve main.mxml, and to directly listen to the event from component 1 and handle it in component 2?
    I need to listen the event in actionscript, not mxml.

    You can dig in to custom event handlers
    Best Regards,
    Yogesh

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

  • Can you send custom events from one form to another?

    I have a compli
    cated application, where I about hundred inp
    uts organized in several input forms. Some of the forms
    require data which has been input in other forms. I have tried to
    dispatch custom events from one form to another, but it dispatches the
    whole form and I only need one or two items.
    Ha anybody else come across such a problem?
    Svend

    One way is to share data in a static singleton

  • Issue in using custom event from outreach

    Hi
    I have created a custom event and executed a scenario successfully for this custom event from ACC. But when I try to configure the same event from Outreach(BCC), I am able to see this custom event in the list of available events, but after selecting this event there is no option to configure attributes for this event, but I can configure attributes in ACC. My BCC version is 10.1.1
    Edited by: 1002715 on Apr 26, 2013 3:06 AM

    Dear Ankit,
    Once the pricing procedure is downloaded, please maintain the document pricing procedure at service contract header level, and maintain the customer pricing procedure at business partner sales area billing data.
    In spro, maintain the pricing procedure for the combination of sales area, document pricing procedure, customer pricing procedure.
    Please crosscheck whether the condition table is active or not.
    Regards,
    Maddy

  • Capture event from mxml component

    I have an accordian control in my main mxml application. Each
    item in the control is a custom mxml component that I created that
    consists of a label and some text. When the label is clicked, I
    need to fire off a message to the containing application with a
    string value. I'm not sure how to do this. Here's what I have right
    now. I'm not sure if I'm going down the right track but if I am,
    how do I pass the string argument with the event and then capture
    this event and the argument in the main application?
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="
    http://www.adobe.com/2006/mxml"
    width="200">
    <mx:Script>
    <![CDATA[
    private var _title:String = "";
    private var _desc:String = "";
    [Inspectable(defaultValue=true)]
    public function set Title(title:String):void{
    _title = title;
    public function set Description(desc:String):void{
    _desc = desc;
    private function SetMovie(url:String):void{
    dispatchEvent(new Event("MovieTitle"));
    [Bindable(event="MovieTitle")]
    ]]>
    </mx:Script>
    <mx:VBox>
    <mx:Label id="lblTitle" text="{_title}" width="190"
    click="SetMovie('testmovie.flv');/>
    <mx:Text id="txtDescription" text="{_desc}"
    width="190"/>
    </mx:VBox>
    </mx:Canvas>

    You have several issues, and several options here. First, a
    custom event can pass any data you want, and is not very hard to
    create.
    However, there is a still easier way. All of the Event
    objects have a "target" and "currentTarget" property which give you
    a reference to the object that dispatched the event.
    So, in your component, implement a public property, say like
    this:
    public function get Title():String{
    return _title;
    then in a handler function you can do:
    private function onMovieTitle(event:Event):void {
    var sMovieTitle:String = event.currentTarget.Title; //watch
    out for reserved words, though
    There are two ways to listen for an event. One easy way is to
    use a bubbling event. Some folks advise against bubbling event
    because of potential event name collisions, but this may not be a
    concern for you. It has not yet concerned me enough to make me
    avoid using bubbling.
    The other way is to declare handler on the component itself.
    Also, if you use a metadata tag, you can assign the handler on the
    mxml tag, instead of using addEventListener():
    <mx:Canvas xmlns:mx="
    http://www.adobe.com/2006/mxml"
    width="200">
    <mx:Metadata>
    [Event(name="MovieTitle", type="flash.events.Event")]
    </mx:Metadata>
    <mx:Script>
    Then, in you main app:
    <myComp id="mc1" ... MovieTitle="onMovieTitle" ...
    Without the metadata, you would do
    mc1.addEventListener("MovieTitle",onMovieTitle)
    Using a bubbling event:
    change the dispatchEvent to this:
    dispatchEvent(new Event("MovieTitle",true)); //the 'true'
    makes it bubble
    Then, in the main app, listen ON the main app(this):
    this.addEventListener("MovieTitle",onMovieTitle);
    Tracy

  • Listening for an event outside of the object...

    Hey, I spent a lot of my day trying to figure out how to
    listen for an event outside of an instantiated object of my own.
    I made my own class called
    Link. When my Link class is instantiated, a Loader object
    (var loader:Loader) is added and it loads a user-specified external
    PNG file. I want to track the Event.COMPLETE event OUTSIDE of my
    Link class, like in my FLA's Actionscript.
    So, I tried a few things without any luck, and by these you
    might get the idea of exactly what I'm trying to do:
    var link1:Link = new Link(...);
    link1.loader.addEventListener(Event.COMPLETE, handler);
    That didn't work, so I tried:
    var link1.Link = new Link(...);
    var loader = link1.getChildByName("loader") as Loader;
    loader.addEventListener(Event.COMPLETE, handler);
    ... that didn't work either. :(
    Any ideas?
    If I am taking the completely wrong approach please do let me
    know. If there's ANY way to know WHEN my loader has completed
    loading its image outside of my Link class...
    Thanks!
    ~ Andrew Merskin

    Let your Link class handle the Loader events. When
    Event.COMPLETE fires,
    just redispatch the event or dispatch a custom event.
    Example 1:
    link1.addEventListener("ALLDONELOADING", linkEventHandler);
    function linkEventHandler(event:Event)
    if(event.type == "ALLDONELOADING")
    // do something or nothing at all
    // Inside your link class you are listening for the load
    complete
    function loadCompleteHandler(event:Event)
    dispatchEvent(new Event("ALLDONELOADING")));
    Example 2:
    link1.addEventListener(Event.COMPLETE, linkEventHandler);
    function linkEventHandler(event:Event)
    if(event.type == Event.COMPLETE)
    // do something or nothing at all
    // Inside your link class you are listening for the load
    complete
    function loadCompleteHandler(event:Event)
    dispatchEvent(event);

  • How to create many objects listening for one event

    I'm experimenting with the EventDispatcher class and I have a
    test class working. I want to use a loop to create a variety of
    movie clips that all listen for an event that gets dispatched every
    half a second. I have the event dispatching properly. My problem is
    that when creating the objects, the temporary variable I use to
    hold each created object has a life that extends beyond the loop in
    which it is instantiated. Rather than all five created objects
    changing color, only the last one changes color (see the code
    below--it lives on the first frame of an FLA file).
    This is not entirely surprising when I look at the code --
    'this' refers to the global scope and 'square' refers to the last
    created object that it pointed to. Here's the resulting trace:
    handler runing, square name is square 4
    this class name is global
    handler runing, square name is square 4
    this class name is global
    handler runing, square name is square 4
    this class name is global
    handler runing, square name is square 4
    this class name is global
    handler runing, square name is square 4
    this class name is global
    How can I modify this code so that each square object changes
    its own color?

    graphics.clear in the context of that function handler in my
    code would refer not to the squares but to the global scope,
    wouldn't it? In which case you'd be clearing all the graphics from
    your top level movie. I tried changing 'square.graphics' to just
    'graphics' in my handler and my squares just remained the original
    steady black.
    Your code doesn't use a loop and therefore isn't re-using a
    variable. You've escaped my 'logical errors' through brute force.
    (BTW, I think my code would work in AS2 if I used the old-school
    draw methods). Suppose you had to create 100 objects? Would you
    want to manually instantiate each one, typing that function over
    and over again? You'd have 500 lines of highly redundant code!
    Maybe try your example using a loop instead? I think you'll
    find it's pretty tough to sneak any vars like 'i' or 'square' from
    the global scope into the handler--the handler refers to the
    living, breathing variable rather than it's value at the time the
    handler was instantiated. Furthermore, you can't sneak any
    information about the square into your handler via the event object
    because the event object is created in a totally different place.

  • How to close a custom form from CUSTOM.pll

    Dear Friends,
    We need your help on the following issue related to Oracle Apps Forms.
    We have a requirement to show a popup message (message should remain open and user should be able to continue working in the order entry form. User use this message as a reference while entering order details) when user enters a customer name or number in the order entry form . This is similar to the Stock Availability form which gets opened automatically when control enters into Order Entry Lines form, where the stock availability form remains open while entering line details.
    To fullfil the requirement, we have designed a custom form with a single text field in which the message text (some customer information) will be shown.
    We are using custom.pll to call this custom form (thru FND_FUNCTION.EXECUTE) when the control leaves customer number field. User could leave this custom form open and continue with entering order details. Till this point we could achieve what we want. i.e. we could show the popup message in the custom form after user enters a customer number.
    The problem is, after the custom form is opened, when we enter a new order for different customer, we need to close the custom form (which is opened for the previous customer) if the customer is not qualified.
    we could not achieve this. We tried using CLOSE_FORM, CLOSE_WINDOW, but did not help.
    Any body have any suggestions on achieving this... Basically, we need your help to know how we can close the custom form from CUSTOM.pll.
    Thanks,
    Uma

    I thing you haven't any (supported) option to close a form via custom.pll.
    For a long time, we have search a solution for the same problem without any result.

  • Custom Event and Custom Expression Deletion in PCW

    Hi Sap Gurus,
    How can i delete the custom event and custom expression created by me in process controlled workflow... I have observed the deletion button grayed out... Is there any other option to delete the custom event and expression.
    Thanks in advance

    Hello Sanjay,
    check below thread:
    BRF - Can not delete expression
    Regards.
    Laurent.

  • I have a iphone 5. How do I search for a event from 2013 under search? I do have "all events" selected

    I have a iphone 5. How do I search for a event from 2013 under search? I do have "all events" selected

    I would check, but I believe I have read that the calendar only lets you search back in the current year. You might find additional information about that in the User Guide. http://manuals.info.apple.com/MANUALS/1000/MA1565/en_US/iphone_user_guide.pdf
    What happens if you go back to a month in 2013, do you see a date with any events in it? I'm not saying the calendar is deleting data, just that you cannot search earlier than the current year.

  • How to dispatch custom events from an item renderer used for Datagrid Column

    Hi,
    I am using an Item Renderer for a Data Grid Column and in that mxml, I am dispatching a custom event with data.
    But the main mxml which has the DataGrid is not able to resolve the event. How can I solve this?
    Thanks

    Hi,
    This is the constructor for Event.
    public function Event(type:String, bubbles:Boolean  = false, cancelable:Boolean  = false)
    When you created your custom event after extending from Event, for the parent container receives the event, the bubbles property must be set to true.
    Please check if you have done so. That should solve the problem. Let me know if it doesn't.
    Nishad

Maybe you are looking for

  • How to make reports on FI Line items

    Hi all, Let me know  how to make reports on FI Line items especially drill down reports. suggest me steps for developing reports through Bex query designer. Am new in reporting on FI. How to make the drilldown reports. Plz let me know step by step. T

  • How can I change the use for iCal

    I currently use iCal so that my iPad, iPhone and iMac are all synch'g.  So far it has worked seemlessly until now at least! My iTunes account is setup under my wife's name so iCal is actually listed through her.  This has never been a problem but I j

  • Why can't I airplay to multiple appletv

    I run a church and want to be able to send my ipad keynote presentation to multiple appletvs in different parts of the building.  There does not appear to be any way to send the signal to more than one appletv at a time.  Is this correct, and if so w

  • CUNIT error in data loading from flat file after r/3 extraction

    Hi all After R/3 business content extraction, if i load data from flat file to info cube, I am getting Conversion exit CUNIT error, what might be the reason, the data in the flat file 0unit column is accurate, and mapping rules are also correct, but

  • Ssh Error: Can't open display:

    Hi all, So I am fairly new to the whole Bash shell business but please bear with me. I am a student working on a research project and need to ssh through one computer into another in order to do my work (one has access to the other). On the second co