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 3807506
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:00:07+00:00 2026-05-19T15:00:07+00:00

In short: I need an event listener in a custom component so all its

  • 0

In short:

I need an event listener in a custom component so all its instances (without editing them) react at the same time, fired by a dispatched event in its parent container.

In detail:

  • I have a custom component with Tab navigator. (The tabs are intended to show different preferences for different Languages.)

  • I have a button bar with buttons for all the languages.

  • There are a lot of instances of the custom component.

I want to click in a button of the languages bar and get ALL the instances switched to the same tab (the custom component contains the logic to change the tab).

I can do it by adding the event listener for EACH INSTANCE of the custom component, so it calls an internal function that changes the tab. But it seems to be very coupled, isn’t it?

I wonder if it can be done in the master CLASS of the component, so it listen for events in its parent container, whichever it is.

In my mind this code shoud work, but it doesn´t (obviously ill’use a custom event to pass the new language value):

this.parent.addEventListener("lang_change", this.change_tab);

This way I can just drop an instance of the component, and see it working for itself.

Thank you in advance

  • 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. Editorial Team
    Editorial Team
    2026-05-19T15:00:08+00:00Added an answer on May 19, 2026 at 3:00 pm

    I need an event listener in a custom
    component so all its instances
    (without editing them) react at the
    same time, fired by a dispatched event
    in its parent container.

    The very thing you want to do, by definition, breaks encapsulation. In an ideal world, a component should know nothing of it’s parent. If the component needs to communicate with it’s parent, it should dispatch an event. IF a parent needs to communicate to children it should call a public method on that child (or change a public property). From an encapsulation stand point, I cannot recommend that the child listen for events on the parent.

    I want to click in a button of the
    languages bar and get ALL the
    instances switched to the same tab
    (the custom component contains the
    logic to change the tab).

    So, then put a click handler for the button and do something like this:

    public function onClick():void{
      myCustomTabNavigator1.selectedIndex = 1 
      myCustomTabNavigator2.selectedIndex = 1 
      myCustomTabNavigator2.selectedIndex = 1 
    }
    

    You can also set the selectedItem if you a reference to it. , If you have your custom TabNavigators in an Array, you can loop over them. IF the custom TabNavigators are child of your custom component you can create a method in that custom component to set the defaults and call that method on each component instead of setting selectedIndex directly.

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

Sidebar

Related Questions

Short explanation of my problem, I need to parse an object and put its
So long story short, i have some forms (2) of them that, need different
Short: I need a right-click event to highlight the cell row. I am using
How can i shorter below codes than before? i need short and simple method:
Why is there a need to convert a value (for example short) to string,
The C code i need to convert into Java is: typedef struct { short
Long story short, client's hosting is using php 5.2.5 and i desperately need to
Short version: For a cache class I need to get notified if an object
I need to run same effect in multi id's in the same page What
In short, my need is to have a background Image in my java app,

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.