Link to home
Start Free TrialLog in
Avatar of sfletcher1959
sfletcher1959Flag for United States of America

asked on

How to get back to the orginal ViewStack after calling a Component

I have created a small application using ViewStack to switch between a dataGrid and an Edit Form. All seems to work ok except I can't figure out out to get back to a ViewStack defined in my main.mxml file from my EditView.

My Save button saves the data to the application server but it doesn't return to the ViewOnly view defined in the main.mxml file. My Cancel button doesn't work at all. :-)

I just can't seem to find a code example of how to do this.
Here are the buttons from my main.mxml file:
 
 <mx:HBox borderStyle="solid" paddingTop="10" paddingBottom="10" 
               paddingLeft="10" paddingRight="10">
                        <mx:Button label="View" click="goToPodDashboard();"/>                        
                        <mx:Button label="Edit" click="myViewStack.selectedChild=EditView;"/>
                        <mx:Button label="Delete"/>
                        <mx:Button label="Exit" click="returnToMagicHome();"/>
                    </mx:HBox>
 
 
Over on my editChartView.mxml file here is my buttons I have defined:
 
 
	<mx:ControlBar id="controlbar1" horizontalAlign="right" verticalAlign="bottom">
			<mx:Button id="searchButton" label="Cancel" click=click="myViewStack.selectedChild=ViewOnly;"/>    
            <mx:Button id="cInfoButton" label="Save" click="submitEdit()"/>    
</mx:ControlBar>

Open in new window

Avatar of zzynx
zzynx
Flag of Belgium image

Is the variable "myViewStack" known in editChartView.mxml?
Can you post where you initialize that variable?
Where's that view stack defined?
All you want is to get the reference of your view stack?

then in editChartView.mxml use the following

var app:main = this.parentApplciation as main;
app.myViewStack; // will be accessible.
Avatar of sfletcher1959

ASKER

The variable "myViewStack" is defined in the main.mxml file. So you are saying that any called components no nothing of the variables defined in main?

This is the only definition of myViewStack and it is in the main.mxml file:

 <mx:ViewStack id="myViewStack" width="100%" height="100%">

This is how I get to the editChartView.mxml:

<mx:VBox id="EditView">      
             <view:editChartView id="editChartView"
                   chart="{dG1.selectedItem}"            
                  resizeEffect="{fadeAndResize}"
                  horizontalScrollPolicy="off"
                  verticalScrollPolicy="off" height="100%">
            </view:editChartView>            
       </mx:VBox>

So what I am beginning to understand is that I have to instantiate "myViewStack" in the editChartView.mxml

I am not sure how to do it. I followed the example by shivaspk but I received the following errors:


1119: Access of possibly undefined property parentApplciation through a reference

1120: Access of undefined property app.

Thanks!


 

>> The variable "myViewStack" is defined in the main.mxml file
So, it's local to that file. It is not known by other mxml files.

If you want other classes to know it, you can pass it to them:

in editChartView.mxml

 
  private _viewStack:ViewStack;

  [Bindable]
  public function set viewStack(viewStack:ViewStack):void {
       _viewStack = viewStack;
  }
  public function get viewStack():ViewStack {
       return _viewStack;
  }

Then you can write in your main:

<view:editChartView id="editChartView"  viewStack={myViewStack}
                  chart="{dG1.selectedItem}"
                  resizeEffect="{fadeAndResize}"
                  horizontalScrollPolicy="off"
                  verticalScrollPolicy="off" height="100%">
</view:editChartView>

then inside editChartView you can use _viewStack (or viewStack since you have a getter too) like:

            click="_viewStack.selectedChild=ViewOnly;"
ASKER CERTIFIED SOLUTION
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> var app:main = this.parentApplciation as main;

There's a typo in.    ( parentApplciation ==== should be ====> parentApplication )

That's probably why you get the error
>> 1119: Access of possibly undefined property parentApplciation through a reference
Hmmm thanks for correcting, I generally don;t use flex builder until and unless absolutely needed.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you don't use Flex Builder "until absolutely needed" what do you use?
no no what I meant was i directly use a simple notepad, infact most of the times I type directly in to the textarea provided by EE, not always I have access to Flexbuilder, especially when I am in office I have no access , hence I type code as is, also sorry for the typo. :)

That is amazing to me, shivaspk! No problem with the typos. I just appreciate all your help!
Thanks again for your assistance!
>> Thanks again for your assistance!
You're welcome.
Thanx 4 axxepting