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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:52:43+00:00 2026-05-21T15:52:43+00:00

I am trying to control the selectedIndex property of a ViewStack on the main

  • 0

I am trying to control the selectedIndex property of a ViewStack on the main application. I have a variable assigned in main.mxml. I am attempting to manipulate that variable through a function in the custom component; viewControl.mxml. I have been able to simulate the effect with a buttonBar, but I would rather it be done with a button.

Main.mxml

<?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" 
           xmlns:comps="comps.*" minWidth="955" minHeight="600">
<fx:Script>
    <![CDATA[
        import comps.viewControl;

        [Bindable]
        public var mainIndex:int = 0;


    ]]>
</fx:Script>

<comps:viewControl id="myControl"/>

<mx:ViewStack id="lgViewStack" selectedIndex="{mainIndex}">

    <s:NavigatorContent id="view1">
        <s:Panel id="firstPanel">
        </s:Panel>
    </s:NavigatorContent>
    <s:NavigatorContent id="view2">
        <s:Panel id="secondPanel">
        </s:Panel>
    </s:NavigatorContent>

</mx:ViewStack>

And the component viewControl.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">

<fx:Script>
    <![CDATA[

        protected function changeView(index:int):void
        {
            mainIndex = index;

        }
    ]]>
</fx:Script>

<s:Button id="myButton" click="changeView(1);"/>

When compiled, I receive the following error message: Access of undefined property mainIndex in viewControl.mxml. Is there something I can do with function set or function get to grab mainIndex from Main.mxml?

  • 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-21T15:52:44+00:00Added an answer on May 21, 2026 at 3:52 pm

    As mentioned in your comment, the variable scope is the issue. There are many ways to do what you need, but essentially you need a place where you can reference both your view stack and your view control in the same scope (aka from another class). There are entire frameworks created simply to provide a way to get these references where you need them, but it happens to be quite simple in your case since the parent component references them both already.

    In your view component, create a local (public and bindable) variable to store the current index based on the button click…

    <?xml version="1.0" encoding="utf-8"?>
    <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
    
    <fx:Script>
        <![CDATA[
    
            [Bindable]
            public var selectedIndex:int;
    
            protected function changeView(index:int):void
            {
                this.selectedIndex = index;
    
            }
        ]]>
    </fx:Script>
    
    <s:Button id="myButton" click="changeView(1);"/>
    

    Then in the parent component you can bind directly to the selectedIndex of the view component…

    <comps:viewControl id="myControl"/>
    
    <mx:ViewStack id="lgViewStack" selectedIndex="{myControl.selectedIndex}">
    </mx:ViewStack>
    

    Another way to do this is to dispatch an event in your viewControl whenever the index changes. You can then do something like this in using an event handler in the parent component…

    protected myControl_changeHandler(event:Event):void
    {
      this.mainIndex = myControl.selectedIndex;
    }
    

    This way you can make sure your parent component has an up to date reference to the index as well…

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

Sidebar

Related Questions

I'm trying to control the main timeline of my flash application from a MovieClip
I have been trying to control a camera through a wsdl file using SUDS.
I am trying to control tabs through a next/previous function. I am using a
I have two divs named arrow and inner. I am trying to control the
I am trying to control a console application (JTAG app from Segger) from Python
I have ICOP VDX-6354 board running Win CE. I'm trying to control the buzzer
Hey guys. I'm working in WinForms and trying to create a ComboBox control that
I'm trying to control windows of a foreign OSX applications from my application. I'd
I have a windows form with a listview control. I have a selectedIndex changed
i have a Flex tree control and im trying to select a tree node

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.