When I added the click="nextQuestion()" it was triggered off the selecting of a 
radio button and not the button. Here all the code I have. It is telling me 
that the viewStack doesn't exist when I believe it should.

test1.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml"; layout="vertical" 
width="100%" height="98%" xmlns:questions="com.ipexpert.questions.q1.*" 
creationComplete="initApp()" >
    <mx:Script>
        <![CDATA[
            import mx.core.Application;    

            public var testID:int = 1;
            public var currentQuestion:int = 0;

            public function initApp():void {

            }        

            public function checkSingle(answer:Object):void {
                if (answer !=0) {
                Application.application.score += 1;
                }
                currentQuestion += 1;
                nextQuestionPlease();
            }

            public function nextQuestionPlease():void {
            }
        ]]>
    </mx:Script>
    <mx:ViewStack id="questionsVS" width="98%" height="100%" paddingLeft="10">

        <questions:question1 />
        <questions:question2 />
        <questions:question3 />
        <questions:question4 />
    </mx:ViewStack>
</mx:Module>

question1.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"; width="98%" height="98%">

    <mx:Script>
        <![CDATA[

            import com.ipexpert.tests.test1;

            public var testMod:test1 = new test1();
        ]]>
    </mx:Script>

    <mx:Label fontWeight="bold" text="1. Which layer(s) of the OSI Reference 
Model provide(s) for internetwork connectivity?" />
    <mx:RadioButtonGroup id="group1" />
    <mx:RadioButton paddingLeft="10" groupName="group1" label="Data Link" 
value="0" selected="true" />
    <mx:RadioButton paddingLeft="10" groupName="group1" label="Physical" 
value="0" />    
    <mx:RadioButton paddingLeft="10" groupName="group1" label="Session" 
value="0" />    
    <mx:RadioButton paddingLeft="10" groupName="group1" label="Network" 
value="1" />    
    <mx:RadioButton paddingLeft="10" groupName="group1" label="Presentation" 
value="0" />    

    <mx:Button label="Next" click="testMod.checkSingle(group1.selectedValue)" />
</mx:VBox>

----------------------------------------
From: Michael Wills <mich...@mawills.com>
Sent: Monday, March 09, 2009 10:55 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a viewStack through actionscript 

Hey there Wally,

You can get access to the currently selected viewstack, and also set it, 

through selectedIndex. So your initial declaration would be like

<mx:ViewStack id="questionVS" etc... selectedIndex="0" 

click="nextQuestion()">

and in your function nextQuestion you can increment the selectedIndex. 

I'd have to check but I think you can find the number of items in your 

viewStack with numChildren. That would give you your max value to finish 

your quiz or handle the end how you would like.

You can find more about what you can do with viewstacks in the docs:

http://livedocs.adobe.com/flex/3/langref/mx/containers/ViewStack.html

Hope that helps!

Michael

Wally Kolcz wrote:

>

> I have a test that I want to walk through the questions using a 

> function. How can I set the inital value of the ViewStack 

> (questionsVS) to 0 and then increment it by one each time someone 

> clicks a button?

>

> <mx:ViewStack id="questionsVS" width="98%" height="100%" paddingLeft="10">

>         <questions:question1 />

>         <questions:question2 />

>         <questions:question3 />

>         <questions:question4 />

>     </mx:ViewStack>

>

> 


Reply via email to