sfletcher1959
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.
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>
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.
then in editChartView.mxml use the following
var app:main = this.parentApplciation as main;
app.myViewStack; // will be accessible.
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="{fadeAndResi ze}"
horizontalScrollPolicy="of f"
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!
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="{fadeAndResi
horizontalScrollPolicy="of
verticalScrollPolicy="off"
</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:ViewSt ack):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="{fadeAndResi ze}"
horizontalScrollPolicy="of f"
verticalScrollPolicy="off" height="100%">
</view:editChartView>
then inside editChartView you can use _viewStack (or viewStack since you have a getter too) like:
click="_viewStack.selected Child=View Only;"
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:ViewSt
_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="{fadeAndResi
horizontalScrollPolicy="of
verticalScrollPolicy="off"
</view:editChartView>
then inside editChartView you can use _viewStack (or viewStack since you have a getter too) like:
click="_viewStack.selected
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> 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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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. :)
ASKER
That is amazing to me, shivaspk! No problem with the typos. I just appreciate all your help!
ASKER
Thanks again for your assistance!
>> Thanks again for your assistance!
You're welcome.
Thanx 4 axxepting
You're welcome.
Thanx 4 axxepting
Can you post where you initialize that variable?
Where's that view stack defined?