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.

Similar Messages

  • 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

  • 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

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

  • 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

  • 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

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

  • Custom Event generation and Handling

    HI all,
    I am new to java. I have a dataset which changes dynamically and this dataset is responsible for some other dataset(s). So whenever the original dataset is modified, the other datasets based on this dataset should be updated automatically so as to preserve the consistency.
    What I want to do is to write a custom event which is to be fired whenever the original dataset is modified and notify it to other datasets so as to ensure the consistency.
    Any help in this regard is extremely appreciated.

    HI Duffymo,
    Here is my problem for better understanding:
    I have a vector data in a NodePanel (this vector data originates from some other datastructure...but that is immaterial as we know that this data is an instance of that datastructure). This vectordata in NodePanel is responsible for another vectordata in SchedulePanel. The NodePanel and SchedulePanel are tabbedPanels in a tabbedframe. Whenever I update the vector data in NodePanel, the vector data in SchedulePanel needs to be updated.
    The solution you gave me, taught me an insight of the event handling in Java.
    I am quoting my source for your reference as I am unable to incorporate your idea into my project.
    Event class:
    import java.util.*;
    public class VectorUpdateEvent extends EventObject
         public VectorUpdateEvent(Object source)
              super(source);
    Interface to EventListener
    public interface VectorUpdateListener
         public void eventVectorUpdated(VectorUpdateEvent event);
    class EventGenerator
    import java.util.*;
    public class VectorUpdateEventIssuer
         implements EventListener
         public VectorUpdateEventIssuer()
              listListeners = new ArrayList();
         public synchronized void addVectorUpdateEventListener(VectorUpdateEvent l)
              listListeners.add(l);
         protected synchronized void removeVectorUpdateEventListener(VectorUpdateEvent l)
              listListeners.remove(listListeners.indexOf(l));
         protected void notifyVectorUpdateEvent(Object source)
              VectorUpdateEvent evt = new VectorUpdateEvent(source);
              Iterator itr = listListeners.iterator();
              while (itr.hasNext())
                   ((VectorUpdateListener)itr.next()).eventVectorUpdated(evt);
         private ArrayList listListeners;
    class where the event originates
    class NodePanel
         extends JPanel
         implements ActionListener, ListSelectionListener
         /////////////Constructors/////////////////////////
         public NodePanel()
              addNodeButton = new JButton("Add Node");
              delNodeButton = new JButton("Delete Node");
              dumpNodeButton = new JButton("Dump Node");
              reloadNodeButton = new JButton("Reload Node");
              browseButton = new JButton("Browse Node");
              exitButton = new JButton("Exit");
              add(addNodeButton);
              add(delNodeButton);
              add(dumpNodeButton);
              add(reloadNodeButton);
              add(browseButton);
              add(exitButton);
              setButtonsEnabled(false);
              addNodeButton.addActionListener(this);
              delNodeButton.addActionListener(this);
              dumpNodeButton.addActionListener(this);
              reloadNodeButton.addActionListener(this);
              browseButton.addActionListener(this);
              exitButton.addActionListener(this);
              nodesVector = new Vector();
              nodesList = new JList(nodesVector);
              this.vectorNodeAttributes = new Vector();
              JScrollPane scrollPane = new JScrollPane(nodesList);
              add(scrollPane,BorderLayout.CENTER);
              nodesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              nodesList.addListSelectionListener(this);
         ////////////////Methods///////////////////////////
         /////////////Event valueChanged///////////////////
         public void valueChanged(ListSelectionEvent evt)
              JList source = (JList) evt.getSource();
              setButtonsEnabled(true);
              desiredNode = (String) source.getSelectedValue();
              if (desiredNode == null)
                   setButtonsEnabled(false);
         //////////////Event actionPerformed////////////
         public void actionPerformed(ActionEvent evt)
              Object source = evt.getSource();
              if (source == addNodeButton)
                   addNodeButtonClicked();
              else if (source == delNodeButton && desiredNode != null)
                   deleteNodeButtonClicked();
              else if (source == dumpNodeButton && desiredNode != null)
                   JFileChooser d = new JFileChooser();
                   //d.setCurrentDirectory("");
                   d.setFileFilter(new XMLFilter());
                   int result = d.showSaveDialog(this);
              else if (source == reloadNodeButton && desiredNode != null)
                   JFileChooser d1 = new JFileChooser();
                   //d.setCurrentDirectory("");
                   d1.setFileFilter(new XMLFilter());
                   int result = d1.showOpenDialog(this);
                   //String filename=d1.getSelectedFile().getName();
              if (source == browseButton && desiredNode != null)
                   browseButtonClicked();
              else if (source == exitButton)
                   System.exit(0);
         //////////Enables or Diables the Buttons////////
         private void setButtonsEnabled(boolean enable)
              delNodeButton.setEnabled(enable);
              dumpNodeButton.setEnabled(enable);
              reloadNodeButton.setEnabled(enable);
              browseButton.setEnabled(enable);
              private void deleteNodeButtonClicked()
              if (noFieldDlg != null)
                   noFieldDlg.dispose();
              noFieldDlg = new NoFieldDialog("Delete the Node?");
              noFieldDlg.show();
              if (noFieldDlg.getDialogResult() == DialogResult.OK)
                   int nodeToRemove=0;
                   for (int i=0; i< vectorNodeAttributes.size(); i++)
                        if(((NodeAttributes)(vectorNodeAttributes.get(i))).getNodeName().compareTo(nodesList.getSelectedValue()) == 0)
                             nodeToRemove = i;
                   vectorNodeAttributes.remove(nodeToRemove);
                   nodesVector.removeElement(nodesList.getSelectedValue());
                   this.nodesList.setListData(nodesVector);
                   NodePanel.nodesPresent = nodesVector;
                   updateStaticNodeList();
    /*************** as soon as the NodePanel.nodesPresent is updated, the changes are to be reflected in the Schedule Panel ******************/
                   VectorUpdateEvent e = new VectorUpdateEvent(this);
                   VectorUpdateEventIssuer v = new VectorUpdateEventIssuer();
                   v.addVectorUpdateEventListener(e);
                   v.notifyVectorUpdateEvent(this);
         ///////////////Data Members////////////////////
         private JButton addNodeButton;
         private JButton delNodeButton;
         private JButton dumpNodeButton;
         private JButton reloadNodeButton;
         private JButton browseButton;
         private JButton exitButton;
         private String desiredNode;
         private OneFieldDialog oneFieldDlg = null;
         private NoFieldDialog noFieldDlg = null;
         private JList nodesList;
         private Vector nodesVector;
         private Vector vectorNodeAttributes;
         private static Vector nodesPresent = null;
    } // end class NodePanel
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    ////////////////Class SchedulePanel////////////////
    class SchedulePanel extends JPanel
    implements ActionListener, ListSelectionListener, VectorUpdateListener
         ////////////////Constructors//////////////////
         public SchedulePanel()
              addScheduleButton = new JButton("Add Schedule");
              delScheduleButton = new JButton("Delete Schedule");
              dumpScheduleButton = new JButton("Dump Schedule");
              reloadScheduleButton = new JButton("Reload Schedule");
              browseScheduleButton = new JButton("Browse Schedule");
              exitButton = new JButton("Exit");
              add(addScheduleButton);
              add(delScheduleButton);
              add(dumpScheduleButton);
              add(reloadScheduleButton);
              add(browseScheduleButton);
              add(exitButton);
              setButtonsEnabled(false);
              addScheduleButton.addActionListener(this);
              delScheduleButton.addActionListener(this);
              dumpScheduleButton.addActionListener(this);
              reloadScheduleButton.addActionListener(this);
              browseScheduleButton.addActionListener(this);
              exitButton.addActionListener(this);
              scheduleVector = new Vector();
              scheduleList = new JList(scheduleVector);
              this.vectorScheduleOperations = new Vector();
              JScrollPane scrollPane = new JScrollPane(scheduleList);
              add(scrollPane);
              scheduleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              scheduleList.addListSelectionListener(this);
              //updateEventListener = new VectorUpdateEventIssuer();
              //updateEventListener.addVectorUpdateEventListener(this);
         /////////////Methods///////////////////////
         ////////////Event valueChanged/////////////
         public void valueChanged(ListSelectionEvent evt)
              JList source = (JList)evt.getSource();
              setButtonsEnabled(true);
              desiredSchedule = (String)source.getSelectedValue();
              if (desiredSchedule == null)
                   setButtonsEnabled(false);
         ////////////Event actionPerformed////////
         public void actionPerformed(ActionEvent evt)
              Object source = evt.getSource();
              if (source == addScheduleButton )
                   addScheduleButtonClicked();
              else if (source==delScheduleButton && desiredSchedule!=null)
                   deleteScheduleButtonClicked();
              else if (source == dumpScheduleButton && desiredSchedule!=null)
                   JFileChooser d = new JFileChooser();
                   d.setFileFilter(new XMLFilter());
                   int result = d.showSaveDialog(this);
              else if (source == reloadScheduleButton && desiredSchedule!=null)
                   JFileChooser d1 = new JFileChooser();
                   d1.setFileFilter(new XMLFilter());
                   int result = d1.showOpenDialog(this);
              else if (source == browseScheduleButton && desiredSchedule!=null)
                   browseScheduleButtonClicked();
              else if (source == exitButton)
                   System.exit(0);
         public void eventVectorUpdated(VectorUpdateEvent event)
              System.out.println("Hello! EventRaised");
         ///////////Data Members//////////////////
         private JButton addScheduleButton;
         private JButton delScheduleButton;
         private JButton dumpScheduleButton;
         private JButton reloadScheduleButton;
         private JButton browseScheduleButton;
         private JButton exitButton;
         private String desiredSchedule;
         private OneFieldDialog oneFieldDlg = null;
         private NoFieldDialog noFieldDlg = null;
         private JList scheduleList;
         private Vector scheduleVector;
         private Vector vectorScheduleOperations;
         private VectorUpdateEventIssuer updateEventListener;
    } // end class SchedulePanel
    I hope you understood my problem now. The NodeAttributes is a datastructure containing the node name and an associated table for that. THe ScheduleOperations is similar to the NodeAttributes but it contains a DefaultTableModel which inturn consists of a column which is filled with the list of current nodes available + their schedules.
    I am sorry for my long posting.
    Thanks once again in anticipation.

  • Dispatching Custom Events Help

    Hello Everyone,
    I am just learning how to handle custom events, and after spending couple of days tring to understand the process, I am unable to get it going. What I am trying to do is to write a Two Button (component/swf). So when I need to utilize this component in other projects, I can simply load the the swf and be able to fire the buttons.
    I have two button objects on the stage, and I would like these two button object to fire custom events when the parent component is loaded as swf in other projects. Perhaps, I am going all wrong about what I am tring to accomplish here, I would highly appreciate your help.
    After some research, I concluded that I will need to employ Custom Event(s) going for my component. I spent hours on google and have not been able to get it working.
    Here is my code:
    ============================
    CustomEvent Class
    ============================
    package com.custom.apps
        import flash.events.Event;
        public class CustomEvent extends Event
            public static const CUSTOM:String = "custom";
            public var arg:*;
            public function CustomEvent(type:String, customArg:*=null, bubbles:Boolean=false, cancelable:Boolean=false)
                super(type, bubbles, cancelable);
                this.arg = customArg;
            public override function clone():Event
                return new CustomEvent(type, arg, bubbles, cancelable);
            public override function toString():String
                return formatToString("CustomEvent", "type", "arg",    "bubbles", "cancelable", "eventPhase");
    ============================
    DISPATCHING THE EVENTS
    ============================
    import com.custom.apps.*;
    btn.addEventListener(MouseEvent.CLICK, clickHandler);
    function clickHandler(e:MouseEvent):void
        dispatchEvent(new Event(CustomEvent.CUSTOM, customHandler));
        //trace("FIRED");
    function customHandler(e:CustomEvent):void
        trace(e.target);
        trace('hello');

    Kalisto,
    I appreciate your help. Do I have this right? So I can build a navigation component with two links:
    LINK1 | LINK2
    then I load this navigation component/swf into another project and when I click on either of the links, it will dispatch a CUSTOM EVENT and when the event is dispatched, lets say I have a  function (sayHello) listening for that particular event and when the CUSTOM EVENT is dispatched when one of the navigation component's link is clicked the (sayHello()) function would fire itself.
    Can this be done? Am I on the right track?
    I have been at it for couple of days now, I am able to dispatch the event but don't know how to have a function listen for the events. I would highly appreciate it if you can have look at my code.
    Thanks a lot

  • Custom event from itemeditor

    Hello, I have a datagrid with a custom itemEditor inside one
    of the columns (a custom textInput).
    I want to dispatch an event that the parent datagrid can
    receive, when the value of this textInput is changed, .
    This is how I have defined my itemEditor in the parent
    DataGrid's DataGridColumn:
    <mx:DataGridColumn headerText="Quantity" editable="true"
    itemEditor="myTextInput" width="63" dataField="Quantity" />
    Here is the instantiation line of my custom TextInput that
    defines a CHANGE event listener:
    <mx:TextInput xmlns:mx="
    http://www.adobe.com/2006/mxml"
    addedToStage="{addEventListener(Event.CHANGE,functionToCall)}">
    That all works fine, but I cannot figure out how to get the
    parent datagrid to receive notification of this change ?
    Thanks kindly for any help.

    "phil1943" <[email protected]> wrote in
    message
    news:gflfep$ons$[email protected]..
    > Hello, I have a datagrid with a custom itemEditor inside
    one of the
    > columns (a
    > custom textInput).
    > I want to dispatch an event that the parent datagrid can
    receive, when the
    > value of this textInput is changed, .
    >
    > This is how I have defined my itemEditor in the parent
    DataGrid's
    > DataGridColumn:
    > <mx:DataGridColumn headerText="Quantity"
    editable="true"
    > itemEditor="myTextInput" width="63" dataField="Quantity"
    />
    >
    > Here is the instantiation line of my custom TextInput
    that defines a
    > CHANGE
    > event listener:
    > <mx:TextInput xmlns:mx="
    http://www.adobe.com/2006/mxml"
    >
    addedToStage="{addEventListener(Event.CHANGE,functionToCall)}">
    >
    > That all works fine, but I cannot figure out how to get
    the parent
    > datagrid to
    > receive notification of this change ?
    http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf
    Q3

  • Dispatching an event from a PDF to AIR?

    I would like to put a button in a PDF using Acrobat, that,
    when clicked, dispatches an event that can be picked up by my
    displaying AIR application. The PDF is being displayed in AIR using
    HTMLLoader in an HTML object.
    Is this possible?

    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

  • Dispatching Custom Event

    Hello everybody,
    Task: I want to enter a message in input text field and
    write it in the dynamic using a custom event dispatching.
    Solution: I have 2 textfields on the stage.
    One textfield is an input text field the other is a dynamic
    text field which will server just to display text.
    on the flash in the first frame I made this code:
    // mb is the instance name of the dynamic text field already
    placed on the stage
    var messageBoard:MsgBoard = new MsgBoard(mb);
    // u1 is the input text field placed on the stage
    var user1:UserInput = new UserInput(u1);
    Also I wrote 3 very simple classes.
    1. UserInput.as // input textfield class that listens to
    input and dispatches a custom event
    2. MsgEvnt.as // custom event class the instance of which is
    dispatched
    3. MsgBoard.as // class that listens to the new event and
    once it occurs adding event message to the textfield
    Problem: Somehow it doesn't work. I actually made it work by
    making a listener the same object that dispatches the event. But I
    want to understand why it doesn't works the way I showed above. I
    browsed a lot of forums and found that all the people use to listen
    by the same object that is dispatching. I think it's like talking
    with yourself isn't it?
    Thanks everybody who will reply and I hope it will help
    someone who will read!

    your event is dispatched within UserInput scope and MsgBoard
    is not within UserInput scope so it's not going to receive that
    event. ie, a UserInput instance is not accessible to MsgBoard.
    you may have a basic misunderstanding: events that are
    dispatched are not like radio signals that are transmitted and
    anyone with a listener (radio) can hear them.
    when you dispatch an event using actionscript, it is
    dispatched by an object (or sometimes by a class) and that event
    can only be detected by the dispatching object (or class).

  • How to dispatch an event from the application to the preloader

    HI everyone
                     I've been searching everywhere on the net, and as far as it goes I gotten no answer for this. When the application hit the preinitialize phase, I'm calling the loadStyle method. As you can see I will hold the CreationComplete event until I the swf is ready. What I want to do, is to have a second loading bar in the preloader (no problem here) to show the progress of the swf downloaded, hence the StyleEvent.PROGRESS event. I would like to know how can I dispatch that event to the preloader?
    ///////////////////APPLICATION
                  import mx.events.StyleEvent;
                import mx.styles.StyleManager;
                private function loadStyle():void
                        var eventDispatcher:IEventDispatcher = StyleManager.loadStyleDeclarations("cl/elmelej/mangiare/estilo/estilo.swf");
                        eventDispatcher.addEventListener(StyleEvent.COMPLETE, completeHandler);
                        eventDispatcher.addEventListener(StyleEvent.PROGRESS,progreso);  
                private function completeHandler(event:StyleEvent):void
                        super.initialized = true;
                private function progreso(event:StyleEvent):void
                override public function set initialized(value:Boolean):void
                    // Hold off until the Runtime CSS SWF is done loading.
    ///////////////////////////////////PRELOADER
    virtual public function set preloader(value:Sprite):void
                _preloader = value;
                value.addEventListener(ProgressEvent.PROGRESS, progressHandler);   
                value.addEventListener(Event.COMPLETE, completeHandler);
                value.addEventListener(StyleEvent.PROGRESS, progressHandlerCSS);  
                value.addEventListener(FlexEvent.INIT_PROGRESS, initProgressHandler);
                value.addEventListener(FlexEvent.INIT_COMPLETE, initCompleteHandler);
    As you can see, the preloader is listening to StyleEvent.PROGRESS  events, but I cant dispatch that event to the preloader so that it can react to it. I hope you can help me. Thanks for your time and help
    Sebastián

    Alex,
             Thank you very much for the fast answer, but I'm not an advanced programmer in Flex, so I would need a bit more help from you. I wouldlike you to tell me if it is possible to do what I want to do? and could you be more specific n the information you gave me please?
    I think you mean something like this:
    private function progreso(event:StyleEvent):void
                  (this.systemManager.getChildAt(systemManager.numChildren) as Preloader).getChildAt(XXXXXXXX).dispatchEvent(event)
    /////////////////////// (this.systemManager.getChildAt(systemManager.numChildren) as Preloader)) -------->gets the preloader 
    ///////////////////////(this.systemManager.getChildAt(systemManager.numChildren) as Preloader).getChildAt(XXXXXXXX)     -------------> would get the progressbar (only If I have XXXXXvalue)      
    let me tell you that the method that I posted on the last message was a part of this class:
         public class PreloaderDisplayBase extends Sprite implements IPreloaderDisplay
    PreloaderDisplayBase is my Preloader.
    I hope you can help me.
    Thanks Again
    Sebastián Toro O

  • Need help with custom event from Main class to an unrelated class.

    Hey guys,
    I'm new to Flash and not great with OOP.  I've made it pretty far with google and lurking, but I've been pulling my hair out on this problem for a day and everything I try throws an error or simply doesn't hit the listener.
    I'm trying to get my Main class to send a custom event to an unrelated class called BigIcon.  The rest of the code works fine, it's just the addEventListener and dispatchEvent that isn't working.
    I've put in the relevant code in below.  Let me know if anything else is needed to troubleshoot.  Thank you!
    Main.as
    package
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        public class Main extends MovieClip
            var iconLayer_mc:MovieClip = new MovieClip();
            public function Main()
                Spin_btn.addEventListener(MouseEvent.CLICK,fl_MouseClickHandler);
                addChildAt(iconLayer_mc,0);
                placeIcons();
            function placeIcons():void
                var i:int;
                var j:int;
                for (i = 0; i < 4; i++)
                    for (j = 0; j < 5; j++)
                        //iconString_array has the names of illustrator objects that have been converted to MovieClips and are in the library.
                        var placedIcon_mc:BigIcon = new BigIcon(iconString_array[i][j],i,j);
                        iconLayer_mc.addChild(placedIcon_mc);
            function fl_MouseClickHandler(event:MouseEvent):void
                dispatchEvent(new Event("twitchupEvent",true));
    BigIcon.as
    package
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.utils.getDefinitionByName;
        public class BigIcon extends MovieClip
            private var iconImage_str:String;
            private var iconRow_int:int;
            private var iconColumn_int:int;
            public function BigIcon(iconImage_arg:String, iconRow_arg:int, iconColumn_arg:int)
                iconImage_str = iconImage_arg;
                iconRow_int = iconRow_arg;
                iconColumn_int = iconColumn_arg;
                this.addEventListener(Event.ADDED_TO_STAGE, Setup);
            function Setup(e:Event)
                this.y = iconRow_int;
                this.x = iconColumn_int;
                var ClassReference:Class = getDefinitionByName(iconImage_str) as Class;
                var thisIcon_mc:MovieClip = new ClassReference;
                this.addChild(thisIcon_mc);
                addEventListener("twitchupEvent", twitchUp);
            function twitchUp(e:Event)
                this.y +=  10;

    Ned Murphy wrote:
    You should be getting an error for the Main.as class due to missing a line to import the Event class...
    import flash.events.Event;
    My apologies, I should attempt to compile my example code before I ask for help...
    Alright, this compiles, gives me no errors, shows my 'book' and 'flowers' icons perfectly when ran, and prints 'addEventListener' to the output window as expected.  I get no errors when I press the button, 'dispatchEvent' is output (good), but the 'twitchUp' function is never called and 'EventTriggered' is never output. 
    How do I get the 'twitchUp' event to trigger?
    Main.as
    package
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import flash.events.*;
        public class Main extends MovieClip
            var iconLayer_mc:MovieClip = new MovieClip();
            var iconString_array:Array = new Array(2);
            public function Main()
                Spin_btn.addEventListener(MouseEvent.CLICK,fl_MouseClickHandler);
                addChildAt(iconLayer_mc,0);
                buildStringArray();
                placeIcons();
            function buildStringArray():void
                var i:int;
                var j:int;
                for (i = 0; i < 2; i++)
                    iconString_array[i] = new Array(3);
                    for (j = 0; j < 3; j++)
                        if (Math.random() > .5)
                            //'flowers' is the name of an illustrator object that has been converted to a MovieClip and is in the library
                            iconString_array[i][j] = "flowers";
                        else
                            //'book' is the name of an illustrator object that has been converted to a MovieClip and is in the library
                            iconString_array[i][j] = "book";
            function placeIcons():void
                var i:int;
                var j:int;
                for (i = 0; i < 2; i++)
                    for (j = 0; j < 3; j++)
                        //iconString_array has the names of illustrator objects that have been converted to MovieClips and are in the library.
                        var placedIcon_mc:BigIcon = new BigIcon(iconString_array[i][j],i*50,j*50);
                        iconLayer_mc.addChild(placedIcon_mc);
            function fl_MouseClickHandler(event:MouseEvent):void
                dispatchEvent(new Event("twitchupEvent",true));
                trace("dispatchEvent");
    BigIcon.as
    package
        import flash.display.MovieClip;
        import flash.events.*;
        import flash.utils.getDefinitionByName;
        public class BigIcon extends MovieClip
            private var iconImage_str:String;
            private var iconRow_int:int;
            private var iconColumn_int:int;
            public function BigIcon(iconImage_arg:String, iconRow_arg:int, iconColumn_arg:int)
                iconImage_str = iconImage_arg;
                iconRow_int = iconRow_arg;
                iconColumn_int = iconColumn_arg;
                this.addEventListener(Event.ADDED_TO_STAGE, Setup);
            function Setup(e:Event)
                this.y = iconRow_int;
                this.x = iconColumn_int;
                var ClassReference:Class = getDefinitionByName(iconImage_str) as Class;
                var thisIcon_mc:MovieClip = new ClassReference;
                this.addChild(thisIcon_mc);
                addEventListener("twitchupEvent", twitchUp);
                trace("addEventListener");
            function twitchUp(e:Event)
                this.y +=  10;
                trace("EventTriggered");
    Output:
    [SWF] Untitled-1.swf - 40457 bytes after decompression
    addEventListener
    addEventListener
    addEventListener
    addEventListener
    addEventListener
    addEventListener
    dispatchEvent
    [UnloadSWF] Untitled-1.swf
    Test Movie terminated.

  • Dispatching an event from an itemRenderer

    Hello everybody,
    I can't find what is the best way to do that with spark.
    I have a SkinnableComponent that implements IDataRenderer (it owns a button called "addBtn"). I am using it as the itemRenderer of a dataGroup. The skin is a copy of ComboBox skin.
    My custom combobox component class (which is using the copied combobox skin) is doing so:
    override protected function partAdded(partName:String, instance:Object):void
         super.partAdded(partName, instance);
         if (instance == dataGroup)
              dataGroup.addEventListener("addItem", dispatchAddItemEvent);
    override protected function partRemoved(partName:String, instance:Object):void
         super.partRemoved(partName, instance);
         if (instance == dataGroup)
              dataGroup.removeEventListener("addItem", dispatchAddItemEvent);
              trace("removing 'addItem' listener on", dataGroup);
    public function dispatchAddItemEvent(e:DynamicEvent):void
         trace("Gotcha!")
    And my ItemRenderer component class has this:
    override protected function partAdded(partName:String, instance:Object):void
         super.partAdded(partName, instance);
         if (instance == addBtn)
              addBtn.addEventListener(MouseEvent.MOUSE_DOWN, dispatchAddItemEvent);
    private function dispatchAddItemEvent(e:MouseEvent):void
         e.stopImmediatePropagation();
         var evt:Event = new Event("addItem", false, false);
         dispatchEvent(evt);
    Result is, i never see "Gotcha!" in the console . And yet i know for sure that my IRs' parent is the same dataGroup from upthere. So i dont really understand what's happening here.
    Now i know that if i do new Event("addItem", true, true) it would work, but i dont like bubbling . Do i HAVE to ???
    Cheers !

    Well, I dont see any other approach, unless the virtualLayout = false is set on the list. If the virtualLayout is false, then each itemrender would catch the event and set the property on itself.

Maybe you are looking for