• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

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

0
sfletcher1959
Asked:
sfletcher1959
  • 5
  • 4
  • 4
2 Solutions
 
zzynxSoftware engineerCommented:
Is the variable "myViewStack" known in editChartView.mxml?
Can you post where you initialize that variable?
Where's that view stack defined?
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
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.
0
 
sfletcher1959Author Commented:
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!


 

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
zzynxSoftware engineerCommented:
>> 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;"
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
In your editChartView.mxml add the below code.

Also note this is not complete code you need to display

may be like app.myViewStack.selectedChild=ViewOnly;

The way we are trying to access the viewstack, is we are getting a parentApplication object and type casting to main as its defined in main.mxml and then displaying approriate view.

So you need to invoke this changeMyView() method on some event may as of now to try a simple button click event.
<mx:Script>
	<![CDATA[
 
public function changeMyView():void
{
var app:main = this.parentApplciation as main;
app.myViewStack.  //this is your viewstack now call which ever view you                //want to display.
}
 
	]]>
</mx:Script>

Open in new window

0
 
zzynxSoftware engineerCommented:
>> 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
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Hmmm thanks for correcting, I generally don;t use flex builder until and unless absolutely needed.
0
 
zzynxSoftware engineerCommented:
Alternative:

The Flex help says:
You can refer to the Application object as mx.core.Application.application from anywhere in the Flex application.

So, in your main add a method:

public function showViewOnly():void {
     myViewStack.selectedChild=ViewOnly;
}

then in your editChartView you can write:

<mx:Button id="searchButton" label="Cancel" click="onSearch()"/>

with

private function onSearch():void {
    mx.core.Application.application.showViewOnly();
}
0
 
sfletcher1959Author Commented:
If you don't use Flex Builder "until absolutely needed" what do you use?
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
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. :)

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now