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

Similar Messages

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

  • Missing Action Event from Custom Component

    Hi JSF Gurus,
    I have two custom components, both extends UICommand and have their
    own renderers. I use them on two seperate pages, say component1 on
    page1 and component2 on page2. And page2 is include inside page2.
    I registered an action listener on component2. When the composite page
    is rendered, I clicked on component2. However, the registered action
    listener was not invoked. Inside the debugging (I'm using IntelliJ
    IDEA 5.0) I set a breakpoint inside the decode method of Renderer2
    (renderer for component2). I do see the componen2 actually as an
    actionLister method binding being set to correct value. I do queue the
    new action event to component2 at the end of the decode method. But
    the action listerner never invoke.
    Any idea what did I miss?
    Thanks,
    Edmond

    Hi Yuki,
    Yeah, after I turn on detail JSF debugging as instructed by the book Core JavaServer Faces, I figured out I had a validation error. That solves the mystery.
    Thanks,
    Edmond

  • Listen for Events from anywhere

    Hello!
    I have an application with a rather complicated component hierarchy.
    How can I have it so that I can listen for events from any component in any component, regardless of who is who's child?
    Thank you!

    You need a broadcasting mechanism.
    Many architecture framework offers this facility, but as a quick hack you can try something like
    public class Broadcaster extends EventDispatcher  ( singleton anti pattern   )
    instance
    then just do Broadcaster.instance.addEventListener or removeEventListener. it's a crappy singleton, but at least it does not hold any global state.
    I've also seen people use Application.application to dispatch/listen globally but really don't like it.
    Note : Use weak references or your views will never be eligible for garbage collections.

  • Listening to Events from inside loaded swf

    In Flash Builder 4 I have a swfLoader with which I load swf files. The swf files that get loaded get created in Flash Pro, and I would like to be able to listen for events from the level that they get loaded from. What would I have to specify in the Flash file for the path? Can't seem to be able to specify the right path.
    Thanks a lot for any help!

    I wouldnt say this is elegant but we have been having issues gaining direct access to the SWF's loaded in via OSMF. However I have done setups where I dispatch an event from a SWF and have it bubble up and catch it on the MediaContainer level. Not elegant but works- otherwise may need to make a custom MediaElement and bypass the SWFElement to gain tighter control - seems like there should be a better way, but I havnt found it.

  • Navigating from Custom Component to Standard Compoent(IUICCON). Getting Exception "Define Component Usage 'Random Component Usage of Standard component'"

    Hi Everyone,
    We have a requirement to
    Navigate from Custom Component to the Standard Component(IUICCON – Contract
    management) on the basis of some conditions.
    We tried navigating with Manual
    as well Dynamic Navigation. The Navigation is happening properly and the Navigation is completed and we are on the Contract
    Management Screen(Standard component View).
    On the Contract Management
    screen (standard Component view), when we click on New Contract Button; it throws dump stating “Define
    Component Usage IUICOBJ”. After debugging we identified that the issue was with the Parent class/ component is getting changed, because of which the usage was not found.
    Appreciate your help.
    Thanks in Advance.
    Regards,
    Bhavikjp.

    Hi Bhavik,
    Check which is the active enhancement set at the runtime in the component_loading BADI.
    If it is anything other than your enhancement set,Set it to your enhancement set .
    Check if the parameter WCF_IGNORE_ENHANCEMT in Tcode SU01 is set to 'A' for the User.
    Regards JP.

  • Listening in main application for event coming from custom component

    I have a custom component that im using for a login.  i watch videos and tutorials on how to pass variables between custom components and application. the problem im having is that must tutorials or explanation have you put the event on the custom component and then it refers to some function within the main app.
    Is there a way to just listen on the main app when that event kicks off? ive been trying for hours and i know there has to be something im missing it cant be that hard. any help i would really appreciate.
    Thanks
    Miguel

    Sounds like you're asking about addEventListener():
         <fx:Script>
              <![CDATA[
                   import mx.events.FlexEvent;
                   protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
                        comp.addEventListener("test", testHandler);
                   private function testHandler(e:Event):void {
                        trace(e);
              ]]>
         </fx:Script>
         <local:TestComponent id="comp"/>
    Add an event listener on your custom component (first string is the 'type' of the event).

  • Error when calling bpm service from custom component

    Hi all,
    I have built a custom component in order to fetch task related data by calling a bpm service inside the method of my custom service.
    This is the error trace i got in audit info.
    "not loading page MSG_PAGE because it is up to date with timestamp 1324331008000
    Script stack dump (user: abc, request: IdcService=CUSTOM_SERVICE&dDocName=ABC018005)
    No resource include or function stack for error. "
    What does this error signify?
    In the service definition of my custom service, I am using MSG_PAGE as my template. Is it related to this why i am facing the error? how do i get to know for a particular  functionality i should use a particular template?
    Please provide your inputs asap.
    Thanks in advance.

    HI jiri,
    Please have a look at the stacktrace and provide me a solution as in how to overcome the error.
    I had included Report.trace in order to check the flow of the program and found that the problem arises when i establish the connection.
    Caused by: java.lang.IllegalArgumentException: interface bpmpackage.TaskQueryService is not visible from class loader
             at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353)
             at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
             at weblogic.wsee.jaxws.spi.ClientInstance.createProxyInstance(ClientInstance.java:143)
             at weblogic.wsee.jaxws.spi.WLSProvider$ServiceDelegate.getPort(WLSProvider.java:855)
             at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:344)
             at weblogic.wsee.jaxws.spi.WLSProvider$ServiceDelegate.getPort(WLSProvider.java:792)
             at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:326)
             at javax.xml.ws.Service.getPort(Service.java:92)
             at bpmpackage.TaskQueryService_Service.getTaskQueryServicePort(TaskQueryService_Service.java:97)
             at package.BPMConnection.getService(BPMConnection.java:58)
             at package.classname.fetchTasks(classname.java:239)
             at package.classname.InboundServiceMethod(classname.java:311)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at intradoc.common.IdcMethodHolder.invokeMethod(IdcMethodHolder.java:86)
             at intradoc.common.ClassHelperUtils.executeMethodReportStatus(ClassHelperUtils.java:324)
             at intradoc.server.ServiceHandler.executeAction(ServiceHandler.java:79)
    Thanks in advance.

  • Capture event from custom.pll?

    Hi friends,
    I've been reading in Developers Guide about events capture (p.787) in custom.pll but I've not found anything about capture the event (or something similar) whe we close a descriptive flexfield window....
    Is there any way to know from custom.pll when a window is closed? The purpose is to make diferents actions when the focus return to the original form.
    Thanks.
    Jose.

    Does the WHEN-FORM-NAVIGATE event fire when closing one form and returning to another? However I am pretty sure that this fires when switching between forms without closing one of them as well.

  • Calling from custom component

    I need to call a switch the viewstack panel from a child of
    it which is a custom login component in separate mxml file after
    authorising, can anyone explain how to do it flex AS3?

    Just listen to the event in the parent itself... and when
    dispatching the event make sure you set bubbles to true.

  • 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 to event within custom class

    I've created a custom class that posts to a web page to authorize a user. How can I listen for an event within the custom class?
    This is my code within my main class.
    var customClass:CustomClass = new CustomClass();
    var testingString = customClass.authorize("[email protected]", "password");
    the fuction "authorize" within the customClass looks like this:
    public function authorize(user:String, password:String):void
      jSession = new URLVariables();
                                  j_Loader = new URLLoader();
                                  jSession.j_username = user;
                                  jSession.j_password = password;
                                  jSend.method = URLRequestMethod.POST;
                                  jSend.data = jSession
                                  j_Loader.load(jSend)
    How can I fire an event within my main class once the j_Loader triggers Event.COMPLETE?

    You can fire an event using the dispatchEvent() function.
    In your main class you assign a listener for the event the CustomClass dispatches after it exists.

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

  • Listen for events from an embedded Swf

    Hi there,
    I have spend so long searching for an answer on the web but can not find any that works, please help!
    I'm not even sure if this is possible but if anyone can guide me in the right direction I would most appreciate it!
    Basically what I would like to do is to load a swf in to my flex application - contrary to my post title it doesnt even have to be embedded - when the loaded swf finishes playing it's animation I want for it to dispatch an event and for flex to listen for that event and trigger a function when the event is captured.
    The animation is made in Flash CS3. I have not used any classes, rather on the last frame I set up an action to dispatch an event like this:
    dispatchEvent(new Event("finishedPlaying"));
    In my Flex Application I load my swf using swfLoader and I add an event listener to it like so:
    mySwfLoader.addEventListener("finishedPlaying", test);
    and my function is like this:
    private function test():void
         trace("it worked!");
    This is not working at all and I'm sure I am missing something but I cant seem to find any straightforward answer on the internet!
    Is it at all possible for a swf made in flash to communicate with flex??
    Since they are both written in AS3, I figured it would be easy but alas!
    If anyone can help me I would most appreciate it, thank you in advance!!
    By the way I have also tried:
    mySwfLoader.content.addEventListener("finishedPlaying", test);
    but no luck....

    You have to wait for the swf to complete loading before adding the event listener.
    When are you adding the event listener?
    mySwfLoader.addEventListener("finishedPlaying", test);
    Have a look at the SWFLoader complete event:
    http://livedocs.adobe.com/flex/3/langref/mx/controls/SWFLoader.html#event:complete

  • Opinion: new Package for every new custom Component?

    Hi there,
    I am just thinking of some possibilities to structurize my Components I made.
    I wonder if it is useful/good programming to define a new package for each new custom Component?
    So if I define a new MyComponent class extending JFrame should I make a new package:
    "mycomponent"
    containing these subfolders:
    "view"
    "model"
    "controler"
    subfolging "controler" in:
    "listeners"
    "adapters"
    "events"
    Is there any sense to do so? I think this would be the best way to structurize one's components.
    But if you do, you have to include millions of packages if you want to use one of these components :(.
    Please post, what you think.
    Thank you
    Sincerely
    Karlheinz Toni

    nope ;). I would most certainly not want to put every file in a single directory.
    But I like sturctured things. If things belong to each other, it should be visible at once, that they have something to to with each other. And the best method I can figure you is putting them in one package.
    The subpackages should be created, because of the model, that is used for all swing componentd (UI-delegete, MVC...) so that each structural component is where it belongs to.
    I don't like it if tere are 100 events one object could possibly create and you don't know the events from the component (of course you can guess by the name Event :)), but if they are in the same package, you would have to scroll a long way to get the thing you want (either m, v or c).
    So this is why I would do it ;).
    Anyway: do includes make the program run slower (I have read many threads about it, but there are way to many opinions, so I would be grateful if you post your opinions here, thx ;).
    Thanks for your answer,
    Sincerely
    Karlheinz Toni
    p.s.: why wouldn't you put them in a seperate directory (just overkill?), would you use classes that are structured like this if you are looking for a implementation of something and find it in this structure?

Maybe you are looking for

  • Is there a way to open SSRS 2005 tree view in a table in a Details row upward?

    Hi. I building some reports with SSRS, and showing data in a table. The table has one Details row that forms at the end multiple rows with the tree view (+ and -). Is there a way to open the tree view upwards and not downwards so that the children of

  • Dhcp client option 60 vendor class windows 7 - HOW TO CHANGE?

    Hi, I would like to change the vendor class (dhcp option 60) on my Windows 7 box (not server). I have a requirement to connect to a dhcp server that requires a unique vendor class that happens to not be "MSFT 5.0". Eventually we are going to be runni

  • Pearl with memory card works until synch with desktop mgr

    I have a Pearl 8130 and a 4gb MicroSD HC card.  The card has been formatted and I used the Roxio software from desktop mgr to move stuff to the card.  All was good.  Now each time I connect the pearl and sync with the desktop software, once I disconn

  • Is Leopard compatible with Photoshop 7

    I just sucked all my files from my old iBook, where I was using photoshop 7 for the last few years, now that it is in my MacBook Pro, it won't work, any suggestions?

  • Upgrading to OS X 10.5

    This isn't as much of a problem as it is a request for advice. I am currently using a late model 12" iBook G4 with a 1.2 Ghz processor, and 1.25GB of RAM. This machine is currently running 10.3.9, and has been since it was bought in late 2004. Unfort