Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 132795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:19:09+00:00 2026-05-11T06:19:09+00:00

Let me start off by saying that I’m pretty new to flex and action

  • 0

Let me start off by saying that I’m pretty new to flex and action script. Anyways, I’m trying to create a custom event to take a selected employee and populate a form. The event is being dispatched (the dispatchEvent(event) is returning true) but the breakpoints set inside of the handler are never being hit.

Here is some snippets of my code (Logically Arranged for better understanding):

Employee Form Custom Component

<mx:Metadata>      [Event(name='selectEmployeeEvent', type='events.EmployeeEvent')] <mx:Metadata> <mx:Script>    [Bindable]    public var selectedEmployee:Employee; </mx:Script> ...Form Fields 

Application

<mx:DataGrid id='grdEmployees' width='160' height='268'             itemClick='EmployeeClicked(event);'> <custom:EmployeeForm      selectEmployeeEvent='SelectEmployeeEventHandler(event)'      selectedEmployee='{selectedEmployee}' />  <mx:Script>     [Bindable] private var selectedEmployee:Employee;  private function EmployeeClicked(event:ListEvent):void     {      var employeeData:Employee;      employeeData = event.itemRenderer.data as Employee;      var employeeEventObject:EmployeeEvent =               new EmployeeEvent( 'selectEmployeeEvent', employeeData);      var test:Boolean = dispatchEvent(employeeEventObject);          //test == true in debugger }     private function SelectEmployeeEventHandler(event:EmployeeEvent):void     {          selectedEmployee = event.Employee; //This event never fires     }    </mx:Script> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:19:10+00:00Added an answer on May 11, 2026 at 6:19 am

    There are a few things conspiring to cause trouble here. 🙂

    First, this declaration in your custom component:

    <mx:Metadata>      [Event(name='selectEmployeeEvent', type='events.EmployeeEvent')] <mx:Metadata> 

    … announces to the compiler that your custom component dispatches this particular event, but you’re actually dispatching it with your containing document, rather than your custom component — so your event listener never gets called, because there’s nothing set up to call it.

    Another thing is that, in list-item-selection situations like this one, the more typical behavior is to extract the object from the selectedItem property of the currentTarget of the ListEvent (i.e., your grid — and currentTarget rather than target, because of the way event bubbling works). In your case, the selectedItem property of the grid should contain an Employee object (assuming your grid’s dataProvider is an ArrayCollection of Employee objects), so you’d reference it directly this way:

    private function employeeClicked(event:ListEvent):void {    var employee:Employee = event.currentTarget.selectedItem as Employee;    dispatchEvent(new EmployeeEvent('selectEmployeeEvent'), employee); } 

    Using the itemRenderer as a source of data is sort of notoriously unreliable, since item renderers are visual elements that get reused by the framework in ways you can’t always predict. It’s much safer, instead, to pull the item from the event directly as I’ve demonstrated above — in which case you wouldn’t need an ’employeeData’ object at all, since you’d already have the Employee object.

    Perhaps, though, it might be better to suggest an approach that’s more in line with the way the framework operates — one in which no event dispatching is necessary because of the data-binding features you get out-of-the-box with the framework. For example, in your containing document:

    <mx:Script>     <![CDATA[          import mx.events.ListEvent;          [Bindable]         private var selectedEmployee:Employee;          private function dgEmployees_itemClick(event:ListEvent):void         {             selectedEmployee = event.currentTarget.selectedItem as Employee;         }      ]]> </mx:Script>  <mx:DataGrid id='dgEmployees' dataProvider='{someArrayCollectionOfEmployees}' itemClick='dgEmployees_itemClick(event)' />  <custom:EmployeeForm selectedEmployee='{selectedEmployee}' /> 

    … you’d define a selectedEmployee member, marked as Bindable, which you set in the DataGrid’s itemClick handler. That way, the binding expression you’ve specified on the EmployeeForm will make sure the form always has a reference to the selected employee. Then, in the form itself:

    <mx:Script>     <![CDATA[          [Bindable]         [Inspectable]         public var selectedEmployee:Employee;      ]]> </mx:Script>  <mx:Form>     <mx:FormItem label='Name'>         <mx:TextInput text='{selectedEmployee.name}' />     </mx:FormItem> </mx:Form> 

    … you simply accept the selected employee (which is marked bindable again, to ensure the form fields always have the most recent information about that selected employee).

    Does this make sense? I might be oversimplifying given that I’ve no familiarity with the requirements of your application, but it’s such a common scenario that I figured I’d throw an alternative out there just for illustration, to give you a better understanding of the conventional way of handling it.

    If for some reason you do need to dispatch a custom event, though, in addition to simply setting the selected item — e.g., if there are other components listening for that event — then the dispatchEvent call you’ve specified should be fine, so long as you understand it’s the containing document that’s dispatching the event, so anyone wishing to be notified of it would need to attach a specific listener to that document:

    yourContainingDoc.addEventListener('selectEmployeeEvent', yourOtherComponentsSelectionHandler); 

    Hope it helps — feel free to post comments and I’ll keep an eye out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, let me start by saying that I am totally new to working
Let me start off by saying that I am completely new with WPF (this
Let me start off by saying that I am very new to WPF and
Let me start off by saying that I am fairly new to php. I
Preface Let me start off by saying that I'm a relatively new programmer and
Ok, let me first start off by saying that I've only ever dealt with
Let me start off by saying Im VERY new to iphone development, but Im
Let me start off by saying, I'm not new to programming but am very
Let me start off by saying that this is my first real Cocoa app.
Let me start off by saying that the code in question is part of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.