Question : Passing combobox var to loaded swf as3

Hi all, I've been building a world cup quiz. I have a combobox that loads a swf with the questions in. On the first swf the user chooses a country which loads a swf onto the stage which contains the questions. I cant work out how to pass the country name from the combobox to the new swf.

my ComboBox and swf load code is as follows:


package {
      
      
      import flash.events.*;
      import flash.display.*;
      import fl.controls.ComboBox;
      import fl.data.DataProvider;
      import flash.net.URLRequest;
      import flash.display.Loader;
      import flash.events.ProgressEvent;

      
      public class yahoo extends MovieClip {
      
                  private var bg:background_mc = new background_mc();
                  private var goal:goal_mc = new goal_mc();
                  private var soccerStars:soccerStars_mc = new soccerStars_mc();
                  /*private var replayBtn:replayBtn_mc = new replayBtn_mc();*/
                  private      var comboBox:ComboBox = new ComboBox();
      
      
                        public function yahoo() {
                              
                              stage.addChild(bg);
                              bg.x = 300;
                              bg.y = 300;
                              
                              stage.addChild(goal);
                              goal.x = 450;
                              goal.y = 180;
                              
                              stage.addChild(soccerStars);
                              soccerStars.x = 10;
                              soccerStars.y = 10;
                              
                              /*stage.addChild(replayBtn);
                              replayBtn.x = 580;
                              replayBtn.y = 40;
                              replayBtn.addEventListener(MouseEvent.MOUSE_DOWN, replay);*/
                              
                              stage.addChild(comboBox);
                              comboBox.x = 200;
                              comboBox.y = 300;
                              comboBox.dropdownWidth = 200;
                              comboBox.width = 200;
                              comboBox.prompt = "Select a nation";
                              comboBox.dataProvider = new DataProvider (worldcupNations);
                              comboBox.addEventListener(Event.CHANGE, changeHandler);
                              
                              
                        }
                        
                        
                        
                        /*Creates the Array of nations*/
                        var worldcupNations:Array = new Array (
                              {label:"Algeria"},
                              {label:"Argentina"},
                              {label:"Australia"},
                              {label:"Brazil"},
                              {label:"Cameroon"},
                              {label:"Chile"},
                              {label:"Cote d'Ivoire"},
                              {label:"Denmark"},
                              {label:"England"},
                              {label:"France"},
                              {label:"Germany"},
                              {label:"Ghana"},
                              {label:"Greece"},
                              {label:"Honduras"},
                              {label:"Italy"},
                              {label:"Japan"},
                              {label:"Korean DPR"},
                              {label:"Korea Republic"},
                              {label:"Mexico"},
                              {label:"Netherlands"},
                              {label:"Nigeria"},
                              {label:"Paraguay"},
                              {label:"Portugal"},
                              {label:"Serbia"},
                              {label:"Slovakia"},
                              {label:"Slovenia"},
                              {label:"South Africa"},
                              {label:"Spain"},
                              {label:"Switzerland"},
                              {label:"Uraguay"},
                              {label:"USA"}
                              
                                                                                
                        );  
                        
                        
                  
                  function changeHandler (e): void {
                        
                        
                        /*Load in external swf */
                        var loadSwf:Loader = new Loader();
                        var requestSwf:URLRequest = new URLRequest("Quiz/Quiz.swf");
                        loadSwf.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
                        loadSwf.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
                        loadSwf.load(requestSwf);
                        
                        
                        
                        /* Add swf to stage */
                        function onCompleteHandler (loadEvent:Event) {
                              
                              stage.addChild(loadEvent.currentTarget.content);
                              
                              
                        }
                        
                        /* Progress tracking*/
                        function onProgressHandler(mProgress:ProgressEvent) {
                              var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
                              trace (percent);
                              
                        }
                        
                  }
      
      }
      
}

Answer : Passing combobox var to loaded swf as3

You'll require to create a receiver function in Quiz file for e.g. named "setCountryName"(cName:string)
And you can store this name in your class variable of Quiz file, for e.g:

private var countryName:String;

// this function will be called by loader SWF (yahoo class)
function setCountryName(cName:String):void
{
      // store it in local variable to send it to database with score
      countryName = cName;
}


And in main application (yahoo class) after load complete of Quiz file (Quiz.swf) you'll call that "setCountryName" of loaded swf by passing comboBox.selectedLabel (which will be selected country name)


Let me know if it works for you, or if possible you can share the source files so that I can create a real code snippet for you.

Random Solutions  
 
programming4us programming4us