Skip to main content
Known Participant
April 20, 2010
Question

a function to go to the next case on the switch...?

  • April 20, 2010
  • 1 reply
  • 519 views

i have created a switch that assign different case to different toggle  buttons. so when each case is activate, it loads a different swf.
so  far it works fine..It's going to be like a sub menu thing, the toggle  button remains activated so viewer know which page they are at right  now..until they click the next toggle button..so on and so on.

but  i've spent hours trying to create a "Next" button, so the activeSection  will jump to the next case on the switch list, activates the next  toggle button, loads next swf.  Like a next page thing.

look  around a lot of examples, but the more i tried, the more i confuse.   so...Please HELP!!!

private function onNavigate( event:NavigationEvent ):void{
         
         var targetId:uint = event.data.id;
        
          switch( targetId ){
           
            case  ID_CONTENT_1:
               gotoSection( ID_CONTENT_1 );
                loadLabel ( ID_CONTENT_1 );
               break;

             case ID_CONTENT_2 :
               gotoSection( ID_CONTENT_2  );
               loadLabel ( ID_CONTENT_2 );
                break;
              
            case ID_CONTENT_3 :
                gotoSection( ID_CONTENT_3 );
               loadLabel (  ID_CONTENT_3 );
               break;
           
             case ID_CONTENT_4 :
               gotoSection( ID_CONTENT_4 );
                loadLabel ( ID_CONTENT_4 );
               break;
            
         }
        
      }
     
     
       private function gotoSection( contentId:uint ):void{
        
          var urlToLoad:String;
        
         switch( contentId  ){
           
            case ID_CONTENT_1:
                _sectionToLoad = ID_CONTENT_1;
               urlToLoad       =  SWF_CONTENT1_URL;
               break;
              
             case ID_CONTENT_2:
               _sectionToLoad = ID_CONTENT_2;
                urlToLoad       = SWF_CONTENT2_URL;
                break;
                 
            case ID_CONTENT_3:
                _sectionToLoad = ID_CONTENT_3;
               urlToLoad        = SWF_CONTENT3_URL;
               break;
              
             case ID_CONTENT_4:
               _sectionToLoad =  ID_CONTENT_4;
               urlToLoad      = SWF_CONTENT4_URL;
                break;
              
            default:
                trace("The contentId " + contentId + " is invalid" );
         
         }
        
         //if there is a currently  active section, transition it out
         if( _activeSection ){
             _activeSection.transitionOut();
         }
        
          //load a section
         TweenLite.delayedCall(  SpriteBase.TRANSITION_TIME, loadSection, [ urlToLoad ] );
        
         
      }
     
      private function loadSection(  sectionToLoad:String ):void{
        
         //if something  else is loading, cancel
         if( _isLoading ){
             _loader.close();
             _loader.contentLoaderInfo.removeEventListener( Event.COMPLETE,        onLoadComplete );
             _loader.contentLoaderInfo.removeEventListener( ProgressEvent.PROGRESS,  onProgress );
         }
        
         trace("Load "+  sectionToLoad )
        
          _loader.contentLoaderInfo.addEventListener( Event.COMPLETE,        onLoadComplete );
          _loader.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS,  onProgress );
         _loader.load( new URLRequest( sectionToLoad )  );
        
         _isLoading = true;
        
          TweenLite.to( tfPercentage, .5, { alpha:1, ease:Quart.easeOut } );
         
      }

each case is assigned to one of a group toggle buttons

public function toggleButton( p_nIndex:uint ):void{
         
         if( _selectedButton ){
             _selectedButton.activate( true );
         }
        
          switch( p_nIndex ){
           
            case 0:
                _selectedButton = button1;
               break;

             case 1:
               _selectedButton = button2;
                break;
                 
            case 2:
                _selectedButton = button3;
               break;     
               
            case 3:
               _selectedButton =  button4;
               break;

         }
        
          _selectedButton.activate( false );
         dispatchEvent( new  NavigationEvent( NavigationEvent.NAVIGATE, { id:p_nIndex } ) );
         
      }

How do I create a function to have it jump to the next case???

any  suggestion will be appreciated!!!

This topic has been closed for replies.

1 reply

Inspiring
April 20, 2010

If I understood you correctly, you just need a class level variable that keeps track of the last case. So, once next button is clicked - it will increment this variable by 1.

jhintwAuthor
Known Participant
April 21, 2010

yeah i thought about that..but sorry for my lack of knowledge in AS3,  i wander how do I assign that.

var currentCase: ???

any  hint?

April 21, 2010

You could use an array containing all cases' IDs:

private var casesArray:Array = new Array(ID_CONTENT_1, ID_CONTENT_2, ID_CONTENT_3, ID_CONTENT_4);

and a function:

private function goToNextCase(currentCase:uint):void

{

     var index:int = casesArray.indexOf(currentCase); // retrieve array index of the current case

     index++; // increase the index by 1 to make it indicate the next case

     if(index == casesArray.length) // loop back to the first element

     {

          index = 0;

          gotoSection( casesArray[index] );

     }else{

          gotoSection( casesArray[index] );

     }


}

Notice that casesArray is a class level var (it's outside any function).