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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:14:33+00:00 2026-06-04T21:14:33+00:00

This is my code on button click. It adds myView to the container. And

  • 0

This is my code on button click. It adds myView to the container. And takes care of fact that all previous instances get removed before adding again. I wanna know, if there is some better way of making this “check” ? I especially wanna have some way to remove the 1s 7 lines of this code ( within comments). It seems like an unrelated block of code in the normal code-flow.

function button_CLICK(e:Event)
{
///////////////////////////////////////////////////
            if ( myView!= null)
            {
                if ( contains(myView))
                {
                    removeChild(myView) ;
                }
            }
/////////////////////////////////////////////////////
            myView = new myView("hello")
            addChild(myView);

}
  • 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-04T21:14:34+00:00Added an answer on June 4, 2026 at 9:14 pm

    it would depend on what the object myView consists of. if, for example, it has its own event listeners you would want to use the condition check to clean up the object before disposing of it so there are no memory leaks.

    function button_CLICK(e:Event):void
    {
        if (myView && contains(myView))
        {
            //clean up myView
    
            removeChild(myView);
        }
    
        myView = new myView("hello");
        addChild(myView);
    }
    

    however, if myView is a simple display object that doesn’t contain any leakable references or event listeners than you could simply reassign the variable to overwrite the previous.

    keep in mind that addChild() places the added display object on top above all others. but regardless if that’s something you’d like to avoid or not, i believe it would be better to assign a default or empty view once instead of addChild(myView) each time the button is clicked.

    function button_CLICK(e:Event):void
    {
        myView = new myView("hello");
    }
    

    i assume your code is for for demonstration because new myView("hello") is going to always be the same object? unless perhaps this object relies on dates or timers to make instances different from previous constructs.

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

Sidebar

Related Questions

i have this code in the button click to show selection image when the
I have this code in the end of link button click: Response.ContentType = application/zip;
This code works anywhere else.. form load, button click, etc. But when I add
On document ready I run this code: jQuery(document).ready(function(){ jQuery('#button').click(function() { jQuery('#contact_form').load(/Users/mge/Downloads/jquery-ajax-1/readme.txt); return false; });
I am unsure why this code will not work. When I click a button
I have this code that has one button that let's me choose an entry
I have this Chrome Extension, it adds a poke all button under your pokes.
I want to display a button that when I click adds to the main
I have jQuery code which looks something like this on Button1 Click $('table.result_grid tbody
If the user manually clicks the 'submit' button, i use this code: if (isset($_POST['submit_findall']))

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.