There are some problems in your code:

1) addEventListener(..) expects second argument as function reference
but in your case you are calling a function(goToScreen(..)) while
subscribing to event and function return value is Void, so events are
not subscribed properly.

2) You are trying to subscribe the same "click" event from three
different places...Which doesn't make sense.

Look at the following code, I have modified it to fit your requirement.


##ModifiedCode##

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"; 
        height="100%" 
        width="100%"
        >

<mx:Script>
<![CDATA[



function goToScreen(event)
{
    var button:Button = event.target;
    var selectedIndex:Number = mainViewStack.selectedIndex;
    var totalScreens:Number = mainViewStack.numChildren;
    
    
    if(button == nextButton)
    {
        selectedIndex  = (selectedIndex < totalScreens - 1) ?
++mainViewStack.selectedIndex : (mainViewStack.selectedIndex = 0);
            
    }
    else if(button == backButton)
    {
        selectedIndex = selectedIndex > 0 ?
--mainViewStack.selectedIndex : selectedIndex;
    }
    
    mainPanel.title = statusLabel.text = "screen" + (selectedIndex + 1);
               
    switch(selectedIndex)
        {
                case 0:
                        backButton.visible = false;             
                        nextButton.label = "Next";
                break;
                        
                default:
                        backButton.visible = true;              
        }
        

}
                
]]>
</mx:Script>
        
                
        <!-- Main Panel (mainViewStack=0) -->
        <mx:Panel id="mainPanel" title="screen1" width="100%"
height="100%" styleName="mainPanel">
                <!-- Main ViewStack -->
                <mx:ViewStack id="mainViewStack" width="100%"
height="100%">
                
                        <!-- mainViewStack.selectedChild=screen1  -->
                        <mx:VBox id="screen1" label="screen1"
width="100%" height="100%" >            
        
                                <mx:Text text="This is screen1."
width="100%"/>
                        </mx:VBox>
                        
                        <!-- mainViewStack.selectedChild=screen2 -->
                        <mx:VBox id="screen2" label="screen2"
width="100%" height="100%" >
                                <mx:Text text="This is screen2."
width="100%"/>                          
                        </mx:VBox>              

                        <!-- mainViewStack.selectedChild=screen3 -->
                        <mx:VBox id="screen3" label="screen3"
width="100%" height="100%" >
                                <mx:Text text="This is screen3."
width="100%"/>
                        </mx:VBox>      

                </mx:ViewStack>
                <!-- End Main ViewStack -->
                        <!-- The Control Bar -->
                        <mx:ControlBar>
                                        <mx:HBox width="50%"
horizontalAlign="left">
                                                <mx:Label
id="statusLabel" text="screen1" width="200"/>
                                        </mx:HBox>
                                        <mx:HBox width="50%"
horizontalAlign="right">
                                                <mx:Button
id="backButton" label="Back" click="goToScreen(event)" visible="false"
/>
                                                <mx:Button
id="nextButton" label="Start" click="goToScreen(event);" />
                                        </mx:HBox>
                        </mx:ControlBar>        
                </mx:Panel>
                <!-- End Main Panel -->
</mx:Application>

 

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of face7hill
Sent: Sunday, October 02, 2005 6:28 AM
To: [email protected]
Subject: [flexcoders] sending arguments to addEventListener

I'm trying to create a wizard based application.  I'm having trouble 
sending arguments to my "back" and "next" buttons using 
addEventListener. 


Basically, when my app loads, in the viewstack, the second screen is 
loaded, i.e. it loads before the user gets a chance to hit the next 
button.  I'm trying to have it load the first screen and then go to 
the 
second screen after the user presses the next button. 


Anyone see what I'm doing wrong? 


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"; 
        height="100%" 
        width="100%"
        >

<mx:Script>
<![CDATA[

function initialize(screenx){
        switch(screenx){
                case screen1:
                        mainPanel.title = "screen1";
                        statusLabel.text = "screen1";
                        backButton.visible = false;             
                        
                        backButton.label = "Back";
                        nextButton.label = "Start";
                        nextButton.addEventListener( "click", 
goToScreen(screen2));
                        break;
                        
                case screen2:
                        mainPanel.title = "screen2";
                        statusLabel.text = "screen2";
                        backButton.visible = true;              
                        
                        backButton.label = "Back";
                        nextButton.label = "Next";
                        nextButton.addEventListener( "click", 
goToScreen(screen3));                   
                        break;
        
                case screen3:
                        mainPanel.title = "screen3";
                        statusLabel.text = "screen3";
                        backButton.visible = true;              
                        
                        backButton.label = "Back";
                        nextButton.label = "Next";
                        nextButton.addEventListener( "click", 
goToScreen(screen1));                   
                        break;                  
        }
}


function goToScreen(x){
        mainViewStack.selectedChild = x;

}
                
]]>
</mx:Script>
        
                
        <!-- Main Panel (mainViewStack=0) -->
        <mx:Panel id="mainPanel" title="" width="100%" height="100%" 
styleName="mainPanel">
                <!-- Main ViewStack -->
                <mx:ViewStack id="mainViewStack" width="100%" 
height="100%">
                
                        <!-- mainViewStack.selectedChild=screen1  -->
                        <mx:VBox id="screen1" width="100%" 
height="100%" creationComplete="initialize(screen1);">          
        
                                <mx:Text text="This is screen1." 
width="100%"/>
                        </mx:VBox>
                        
                        <!-- mainViewStack.selectedChild=screen2 -->
                        <mx:VBox id="screen2" width="100%" 
height="100%" creationComplete="initialize(screen2);">
                                <mx:Text text="This is screen2." 
width="100%"/>                          
                        </mx:VBox>              

                        <!-- mainViewStack.selectedChild=screen3 -->
                        <mx:VBox id="screen3" width="100%" 
height="100%" creationComplete="initialize(screen3);">
                                <mx:Text text="This is screen3." 
width="100%"/>
                        </mx:VBox>      

                </mx:ViewStack>
                <!-- End Main ViewStack -->
                        <!-- The Control Bar -->
                        <mx:ControlBar>
                                        <mx:HBox width="50%" 
horizontalAlign="left">
                                                <mx:Label 
id="statusLabel" text="" width="200"/>
                                        </mx:HBox>
                                        <mx:HBox width="50%" 
horizontalAlign="right">
                                                <mx:Button 
id="backButton" label="Back" click="" />
                                                <mx:Button 
id="nextButton" label="Next" click="" />
                                        </mx:HBox>
                        </mx:ControlBar>        
                </mx:Panel>
                <!-- End Main Panel -->
</mx:Application>





--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links



 





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/nhFolB/TM
--------------------------------------------------------------------~-> 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to