View Full Version : viewStack + load component function

11-08-2006, 01:34 PM

I have a main mxml file "main.mxml" containing a view stack linking to an additional 2 mxml components:

<mx:ViewStack id="viewStack_vs">
<mi:page1 id="page_1" label="this is page 1"/>
<mi:page2 id="page_2" label="this is page 2"/>
<mi:page3 id="page_3" label="this is page 3"/>
<mi:page4 id="page_4" label="this is page 4"/>

when an item within the viewStack is selected / clicked… I want to call a function within the component that is selected….

For example within page2.mxml there is a function called testFunc():

Public function testFunc(){
Alert.show(“hello world”)

and then the link “page 2” is selected / clicked from the viewStack, I want to run this fuction within the page2.mxml component….

Is this possible??? Is t here some sort of onClick event within the viewStack I can use???


11-08-2006, 02:50 PM
Yes, there's a click event for ViewStacks (and most everything else).

import mx.controls.Alert;

private function myFunction(event:Event):void
Alert.show("here!","My Title");
<mx:ViewStack click="myFunction( event )">


One of my favorite events :D

10-14-2007, 05:27 PM
Hello, but is there a way to call a function within the viewStack???

10-15-2007, 05:16 PM
The "show" or "change" events might be better choices. If the function you want to call is public, you can do it in the MXML file that the ViewStack is in, yes. This should help get you started:

<mx:ViewStack id="stack" change="if(stack.selectedIndex == 1) page_2.myFunction()">