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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:24:40+00:00 2026-05-31T04:24:40+00:00

I have the following code to create a ViewStack which is used as a

  • 0

I have the following code to create a ViewStack which is used as a dataprovider for a TabBar:

    <s:TabBar id="objectTab" dataProvider="{vs_objects}"/>
       <mx:ViewStack id="vs_objects" width="100%" />

I want to constrain the number of children the ViewStack to avvoid the tabs going out of the screen when the user opens many tabs without closing any. I attempt to do this by removing the oldest element in the ViewStack when the user opens a new tab and the size of the ViewStack is above 9.

private function openTab(object:Object): void {
  //Create a new NavigatorContent(form) and add it to the ViewStack
  ........
  vs_objects.addChild(form);
  if(vs_objects.numChildren > 9) {
    vs_objects.removeChildAt(0);     
  }
  //vs_objects.selectedChild = form;
  vs_objects.selectedIndex = (vs_Tiltaksbanken.numChildren -1);
}

The image below illustrates my problem, where the dark grey color illustrates the selected Tab. There should only be one selected tab, which works perfectly fine with both the child selection approaches above, when i don’t remove a child before selecting a new. When i remove a child and then open a new Tab, the new Tab does not get selected properly, it only gets “painted” in the selected color. In This case Tab 40 is still shown when i open Tab 41 (exceeding 9 tabs). The result of this issue is that Tab 41 is not rendered completely.

enter image description here

Does anyone know how i can fix this problem, or have a different approach for constraining the number of Tab‘s/ViewStack-children?

UPDATE:
The problem was my AS3 code inside the childrens NavigatorContent‘s that caused the application to behave this way. The solution was using the callLater method:

The solution to my problem was using the callLater method as shown below with Adnan Doric‘s code example:

 protected function openTab():void
 {
    var form:Container = new Container();
    form.name = "Tab " + counter++;
    vs_objects.addChild(form);
    vs_objects.selectedChild = form;
    callLater(removeTab);
 }
 private function removeTab(): void {
    if (vs_objects.numElements > 10)
      vs_objects.removeElementAt(0);
 }
  • 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-31T04:24:41+00:00Added an answer on May 31, 2026 at 4:24 am

    Try this, even though I’m not sure it is the correct solution, maybe it’s better to implement some kind of scrolling.

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    
        <fx:Script>
            <![CDATA[
                import mx.core.Container;
    
                private var counter:int = 1;
    
                protected function openTab():void
                {
                    var form:Container = new Container();
                    form.name = "Tab " + counter++;
                    vs_objects.addChild(form);
                    if (vs_objects.numElements > 10)
                        vs_objects.removeElementAt(0);
                    vs_objects.selectedChild = form;
                }
    
            ]]>
        </fx:Script>
    
        <s:TabBar id="objectTab" top="32" labelField="name" dataProvider="{vs_objects}"/>
        <mx:ViewStack id="vs_objects" width="100%" />
        <s:Button label="addTab" click="openTab()" />
    </s:Application>
    

    Hope that helps 🙂

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

Sidebar

Related Questions

I have used following code to create a simple PDF file. It executes fine
I have used the following code to create the XML Document : procedure TForm1.btnCreateXMLClick(Sender:
I have used the following code to create a file in a temp location
I have the following code to create an NSTimer which should update a label
I have the following code to create a UIPickerView: pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0f,
I have the following test-code: CREATE TABLE #Foo (Foo int) INSERT INTO #Foo SELECT
I have the following code to create and apply a few styles for a
I have the following code: // GET: /PlayRoundHole/Create public ActionResult Create(int id) { DB
I have the following code: // // POST: /PlayRoundHole/Create [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(FormCollection collection)
I have the following code: MemoryStream ms = new MemoryStream(); XmlWriter w = XmlWriter.Create(ms);

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.