Switching selectedIndex with button component?

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"? > MainIndex = myControl. SelectedIndex; } This way you can make sure your parent component has an up to date reference to the index as well.

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... Then in the parent component you can bind directly to the selectedIndex of the view component... 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...

That worked just the way I needed. You defined and bound a variable inside the component and accessed it on the parent through the component objects newly created property, in this case the variable selectedIndex. Is that correct?...its all starting to come together now.Thanks.

– totbar Apr 19 at 23:09 I'd like to add that this is good, I would use a bubbling event instead for more malleability since right now the viewstack is completely dependent on that one view which I doubt is what he's trying to accomplish (think 'next' buttons on each view). Also, steve, you definitely need to read up on more basic software principles as classes, object orientation, etc – J_A_X Apr 20 at 12:12 I agree. I was just trying to keep it fairly basic.

Baby steps. :) – drkstr Apr 22 at 23:22.

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. And the component viewControl. 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.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions