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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:44:34+00:00 2026-06-11T12:44:34+00:00

I have a few different question and i have decided to put them in

  • 0

I have a few different question and i have decided to put them in one. So the first question : If i have one and the same code(for example):

buttonsA.buton1a.addEventListener(MouseEvent.MOUSE_DOWN , buton1a_function);
buttonsA.buton2a.addEventListener(MouseEvent.MOUSE_DOWN , buton2a_function);
buttonsA.buton3a.addEventListener(MouseEvent.MOUSE_DOWN , buton3a_function);
buttonsA.buton4a.addEventListener(MouseEvent.MOUSE_DOWN , buton4a_function);
buttonsA.buton5a.addEventListener(MouseEvent.MOUSE_DOWN , buton5a_function);
buttonsA.buton6a.addEventListener(MouseEvent.MOUSE_DOWN , buton6a_function);
buttonsA.buton7a.addEventListener(MouseEvent.MOUSE_DOWN , buton7a_function);
buttonsA.buton8a.addEventListener(MouseEvent.MOUSE_DOWN , buton8a_function);
buttonsA.buton9a.addEventListener(MouseEvent.MOUSE_DOWN , buton9a_function);
buttonsA.buton10a.addEventListener(MouseEvent.MOUSE_DOWN , buton10a_function);

and i want to put it in several places(in different conditions) can i put them in a function a call a function instead a copying a large amout of text (I thought about ‘include’ from a different file but i want to keep all the information in one file).

The second question is about arrays : In my situation i have an array and i .push() a different numbers in it.But it could be “1,51,11,2,13′ or “1,2,3,4,5” so every time place of numbers (and numbers themselves) are different. How can i say to AS3 in function to remove(.splice) exactly the number 5 or 6 (in spite of their place in the array).

The third question is again about the “code” that is upper in the question. Can i maybe with the loop for to make all these 10 addEventListen with a fewer code (i think it should be something like that:)

    for(var i:int = 1; i <= 100; i++){
   //buttonsA.buton'i'a.addEventListener(MouseEvent.MOUSE_DOWN , buton'i'a_function);
    }

Long story short maybe i didn’t have to put so much question and maybe my thoughts are not correct, but i think that my questions are easy but i can’t solve them. Any decisions and replies are welcomed 🙂 Thanks.

  • 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-06-11T12:44:35+00:00Added an answer on June 11, 2026 at 12:44 pm

    First Question:

    Not sure I understand your first question. I’ll take a stab at it and say you’re wanting the functionality of the button mouse down to be enabled during different contexts of your application state, but you don’t want to repeat all the event listeners all the time?

    if so, you should make a subclass for all your button to inherit from. It could look something like this:

    public class ButtonSubClass extends Sprite {  //or simple button, or whatever
        public function ButtonSubClass():void {
            this.addEventListener(MouseEvent.MOUSE_DOWN,downHandler,false,0,true);
        }
    
        private function downHandler(e:MouseEvent):void {
            //do something common to all your buttons here
        }
    }
    

    Then, have all your buttons inherit from this class.

    Second Question:

    function removeFromArray(elementVal:*):void {
        var index:int = array.indexOf(elementVal);  //get the index of the first element whose value is the passed parameter;
        if(index >= 0){
            array.splice(index,1); //remove that element/index from the array.
        }
    }
    

    Third Question:

    If ButtonA is a sprite whose only children are all the buttons you want the listener for, then you can do this:

    var i:int = buttonA.numChildren;
    while(i--){
        buttonsA.getChildAt(i).addEventListener(MouseEvent.MOUSE_DOWN , button_function);
    }
    
    function button_function(e:Event):void {
        switch(e.currentTarget){
            case button1a:
                //do something with button 1a
                break;
    
            case button2a
                //do something with button 2a
                break;
        }
    }
    

    OR, more sloppily and less efficient and not recommended, this:

    for(var i:int=1;i<=10;i++){
        this["buton" + i.toString() + "a"].addEventListener(MouseEvent.MOUSE_DOWN, this["buton" + i.toString() + "a_function"]); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few different applications that i need to share code between to
We have a few different programs all compiled together in the same suite, recently
I have a virtual server with one IP address, serving a few different sites.
we have quite a few projects that use the same codebase (backend code). Just
I have found a few different questions that pertain to my question, but I'm
I have a few different problems going on, I hope though this example is
I am writing an application, where I do have few different windows implemented, where
I have a few different things open in the terminal whenever I'm developing --
I have a few different classes which origin is a another class. I have
Background : I have a few different threads which each need to write to

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.