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

  • Home
  • SEARCH
  • 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 6338333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:25:25+00:00 2026-05-24T19:25:25+00:00

I have created a custom component that I am using, more conveniently, as a

  • 0

I have created a custom component that I am using, more conveniently, as a SkinnablePopUpContainer and I want to use the same function that calls and receives data from it for several Buttons in the UI. What is the best way to achieve this without having to create a new function for each button?

<fx:Script>
        <![CDATA[
            import spark.events.PopUpEvent;

            protected function button1_clickHandler(event:MouseEvent):void
            {

                popup.addEventListener(PopUpEvent.CLOSE, onPopUpEventClose1, false, 0, true);
                popup.open(this);

            }

            private function onPopUpEventClose1(event:PopUpEvent):void {
                popup.removeEventListener(PopUpEvent.CLOSE, onPopUpEventClose1);
                trace(event.commit);
                trace(event.data);
                button1.label=event.data;
            }

            protected function button2_clickHandler(event:MouseEvent):void
            {

                popup.addEventListener(PopUpEvent.CLOSE, onPopUpEventClose2, false, 0, true);
                popup.open(this);

            }

            private function onPopUpEventClose2(event:PopUpEvent):void {
                popup.removeEventListener(PopUpEvent.CLOSE, onPopUpEventClose2);
                trace(event.commit);
                trace(event.data);
                button2.label=event.data;
            }


        ]]>
    </fx:Script>

    <s:Button id="button1" x="102" y="103" label="Button 1 Numbers"
              click="button1_clickHandler(event)"/>
    <s:Button id="button2" x="102" y="200" label="Button 2 Numbers"
              click="button2_clickHandler(event)"/>

You can see how I would rather have one set of functions that can handle all of this rather than manually coding each function.

Is there a way to get the id of the component that calls the function? What’s the best way to solve this?

EDIT: SOLUTION

I have been able to replace all of that code with the trimmer following:

            private var buttonPick:Button;


        public function button_clickHandler(button:Button):void
        {
            switch (button) {
                case button1: popup.addEventListener(PopUpEvent.CLOSE, onPopUpEventClose, false, 0, true);
                    popup.open(button);
                 break;
                case button2: popup.addEventListener(PopUpEvent.CLOSE, onPopUpEventClose, false, 0, true);
                    popup.open(button); break;

            }
            buttonPick = button;

        }

        private function onPopUpEventClose(event:PopUpEvent):void {
            popup.removeEventListener(PopUpEvent.CLOSE, onPopUpEventClose);
            trace(event.commit);
            trace(event.data);

            buttonPick.label=event.data;
        }

and this as the mxml:

<s:HGroup click="button_clickHandler(event.target as Button)">


<s:Button id="button1" x="102" y="103" label="Button 1 Numbers"
          />
<s:Button id="button2" x="102" y="200" label="Button 2 Numbers"
          />
</s:HGroup>

Thanks for the input and advice! And if there is a more efficient way to do it than with case statements, be sure to suggest it!

  • 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-24T19:25:27+00:00Added an answer on May 24, 2026 at 7:25 pm

    You should put those buttons into a common container and listen for clicks on that container. Then you can use Event#target to detect which element in the container was clicked.

    Your buttons in a common container:

    <s:Group click="button_clickHandler(event.target as Button)">
        <s:Button id="button1" x="102" y="103" label="Button 1 Numbers" />
        <s:Button id="button2" x="102" y="200" label="Button 2 Numbers" />
    </s:Group>
    

    The event handler:

    protected function button_clickHandler(button:Button):void {
        switch (button) {
            case button1: trace('clicked button 1'); break;
            case button2: trace('clicked button 2'); break;
            default: trace('clicked somewhere else in the group'); break;
        }
    }
    

    As you can see, I cast event.target to a Button class using the ‘as’ keyword. This way, if you click anything else than a Button, the ‘button’ argument will be ‘null’.

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

Sidebar

Related Questions

I'm using Joomla 1.5. I have created a custom component that pulls data out
I have created a custom control using VB.NET in Visual Studio 2008 that gives
I am using Joomla 1.5 . I have developed a custom component that's basically
I have created a small flash CS4 project that has a few custom components
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a custom TitleWindow whcih i use as a popup. The contents
I have created a custom workflow activity that copies attachments from a case to
I have created a custom tag that looks like this: def textField = {
I have a custom component that is a combination of LinearLayout + ImageViewx2 +

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.