We help IT Professionals succeed at work.

Passing combobox var to loaded swf as3

Alex500
Alex500 asked
on
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);
                              
                        }
                        
                  }
      
      }
      
}
Comment
Watch Question

Well you could define an Interface providing setters for your variables and let your class yahoo implement this interface. You can then set the value from the parent by yahoo({objectReference}).{variableName} = {variableValue}

Here's a short link to some documentation to using interfaces:
http://livedocs.adobe.com/flex/3/html/help.html?content=mxmlcomponents_advanced_5.html

Author

Commented:
Yeh i got completely lost in that documentation. can you not just do some sort of post function to the new swf so say as it loads in the new swf from selection it just sends the country name so that its set up in a var called country or something?
Hi Alex,

Christofer's suggestion is good to implement an interface.

But if you are not familiar with interface's, you can make some raw fixes to it.

Create a function in child swf (Quiz.swf)'s document class as follow (for e.g:)
function setCountryName(cName:String):void
{
      //do whatever is needed
}

and call this function on load complete event in parent swf (Yahoo class), modify complete handler as follows:

 /* Add swf to stage */
                        function onCompleteHandler (loadEvent:Event) {
                             
                              stage.addChild(loadEvent.currentTarget.content);
                              // type cast the loaded content as per document class or base class
                              // in following e.g. i am considering that your base class is MovieClip
                              (loadEvent.currentTarget.content as MovieClip)..setCountryName(comboBox.selectedLabel);
                             
                        }

Let me know if it helps or not.

Author

Commented:
Sorry I don't quite follow what you mean

Author

Commented:
also how would i make it so that I could hold is a variable called country in the new swf so that i can send it to the database with the users quiz score
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.

Author

Commented:
Would it it be possible for you to write the two functions on here?  My two main classes for the quiz swf are bellow. As you can see there is database stuff going on and it will probably give you a clearer idea of what im trying to do
/*Scripted by Alexander Vince June 2010*/
package {

    import flash.display.Sprite;
    import fl.controls.Button;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
	import flash.text.*;
	import flash.events.*;
	import flash.display.*;
	import fl.controls.TextArea;
	import fl.data.DataProvider;
	import flash.net.URLRequest;
	import flash.display.Loader;
	import flash.events.ProgressEvent;
	import flash.net.URLVariables;
	import flash.net.URLLoader;
	import flash.net.URLRequestMethod;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	//tweener libraries
	import caurina.transitions.*;

	

    public class QuizApp extends MovieClip {
		
		//Load in Movie Clips
		private var nextBtn:nextbtn_mc = new nextbtn_mc();
		private var prevBtn:prevbtn_mc = new prevbtn_mc();
		private var finishBtn:finishbtn_mc = new finishbtn_mc();
		
		private var searchBox:searchArea_mc = new searchArea_mc();
		private var searchBtn:search_btn = new search_btn();
		
		//Load the bars in
				private var sideBar:SideBar_mc = new SideBar_mc;
		
				private var bar:bar_mc = new bar_mc();
				private var barTwo:bar_mc = new bar_mc();
				private var barThree:bar_mc = new bar_mc();
				private var barFour:bar_mc = new bar_mc();
				private var barFive:bar_mc = new bar_mc();
				
				private var graphBar:graphBar_mc = new graphBar_mc;
				private var top5Fans:top5Fans_mc = new top5Fans_mc;
				
				private var northKorea:northKorea_mc = new northKorea_mc();
				private var england:england_mc = new england_mc();
				private var germany:germany_mc = new germany_mc();
				private var cameroon:cameroon_mc = new cameroon_mc();
				private var japan:japan_mc = new japan_mc();
				
				
				//Text formating
				private var countryOne:TextField;
				private var countryOneScore:TextField;
				
				private var countryTwo:TextField;
				private var countryTwoScore:TextField;
				
				private var countryThree:TextField;
				private var countryThreeScore:TextField;
				
				private var countryFour:TextField;
				private var countryFourScore:TextField;
				
				private var countryFive:TextField;
				private var countryFiveScore:TextField;
				
				
				private var formatCountry:TextFormat = new TextFormat("Verdana", 14, 0xfecd08);
				private var formatScore:TextFormat = new TextFormat("Verdana", 14, 0xffffff);
							
							
							
							
							
		
		
		private var formatError:TextFormat = new TextFormat("Verdana", 14, 0xffffff);  
		
        //for managing questions:
        private var quizQuestions:Array;
        private var currentQuestion:QuizQuestion;
        private var currentIndex:int = 0;
        //the buttons:
        private var prevButton:Button;
        private var nextButton:Button;
        private var finishButton:Button;
        //scoring and messages:
        private var score:int = 0;
        private var statusText:TextField;
		
		

        
		
		public function QuizApp() {
    	addEventListener(Event.ADDED_TO_STAGE, addedHandler);
		
		
	}
	
	
	
	
	public function yahooConstructor () {
		
		
		stage.addChild(searchBox);
		searchBox.x = 325;
		searchBox.y = 565;
		
		stage.addChild(searchBtn);
		searchBtn.x = 484;
		searchBtn.y = 559;
		searchBtn.addEventListener(MouseEvent.CLICK, doSearch);
	
	}
	
		/* Yahoo Search */
	
			private function doSearch(evt:MouseEvent) {
				var str:String;
	
				if(searchBox.text == "" || !searchBox.finishedTyping){
				str = searchBox.autoText;
				} else {
				str = searchBox.text;
					}
					
					var url:String = "http://uk.search.yahoo.com/search?vc=&p=" + str + "&ei=UTF-8";
  					var request	:URLRequest = new URLRequest(url);
					navigateToURL(request, '_blank');
	
				}
	
		
		private function addedHandler(event:Event):void {
			quizQuestions = new Array();
			createQuestions();
			createButtons();
			createstatusTextBox();
			addAllQuestions();
			hideAllQuestions();
			firstQuestion();
			yahooConstructor();
		
		}
		
		
        private function createQuestions() {
            quizQuestions.push(new QuizQuestion("Which Algerian centre-half currently plays his football in Scotland for Glasgow Rangers?",
                                                            1,
                                                            "Madjid Bougherra",
                                                            "Antar Yahia", 
                                                            "Lounes Gaouaoui"));
            quizQuestions.push(new QuizQuestion("How Many Times have Argentina won the World Cup?",
                                                            2,
                                                            "1",
                                                            "2",
                                                            "3"));
            quizQuestions.push(new QuizQuestion("Australia open their World Cup campaign against which team?",
                                                            2,
                                                            "Germany",
                                                            "France",
                                                            "Brazil"));
            quizQuestions.push(new QuizQuestion("Ronaldo won the Golden boot in the 2002 World Cup, how many goals for Brazil did he score?",
                                                            3,
                                                            "6",
                                                            "8",
                                                            "10"));
			quizQuestions.push(new QuizQuestion("How many goals did Cameroon score on road to the World Cup finals in South Africa?",
                                                            1,
                                                            "23",
                                                            "15",
                                                            "20"));
			quizQuestions.push(new QuizQuestion("Chile are ranked in which position according to Fifa rankings?",
                                                            3,
                                                            "10th",
                                                            "18th",
                                                            "15th"));
			quizQuestions.push(new QuizQuestion("Ivory Coast are also known as?",
                                                            3,
                                                            "Lions",
                                                            "Tigers",
                                                            "Elephants"));
			quizQuestions.push(new QuizQuestion("Which current Danish international is the 2nd highest goalscorer in his nations history?",
                                                            2,
                                                            "Nicklas Bentdner",
                                                            "Jon Dahl Tomasson",
                                                            "Christian Poulsen"));
			quizQuestions.push(new QuizQuestion("Who will be the oldest English player at this years World Cup finals?",
                                                            1,
                                                            "David James",
                                                            "John Terry",
                                                            "Frank Lampard"));
			quizQuestions.push(new QuizQuestion("Which former France national captain will become manager after the 2010 world cup?",
                                                            1,
                                                            "Laurent Blanc",
                                                            "Patrick Vieira",
                                                            "Didier Deschamps"));
        }
        private function createButtons() {
            var yPosition:Number = stage.stageHeight - 250;

            /*prevButton = new Button();
            prevButton.label = "Previous";*/
           	prevBtn.x = 100;
            prevBtn.y = yPosition;
            prevBtn.addEventListener(MouseEvent.CLICK, prevHandler);
            addChild(prevBtn);

           //nextBtn = new Button();
            //nextButton.label = "Next";
            nextBtn.x = 250;
            nextBtn.y = yPosition;
            nextBtn.addEventListener(MouseEvent.CLICK, nextHandler);
            addChild(nextBtn);

           /* finishButton = new Button();
            finishButton.label = "Finish";*/
            finishBtn.x = 400;
            finishBtn.y = yPosition;
            finishBtn.addEventListener(MouseEvent.CLICK, finishHandler);
            addChild(finishBtn);
        }
		
		
		//Styles error messaging
        private function createstatusTextBox() {
            statusText = new TextField();
            statusText.y = stage.stageHeight - 210;
			statusText.width = 500;
			statusText.x = 400;
            addChild(statusText);
        }
		
		
		
        private function showMessage(theMessage:String) {
            statusText.text = theMessage;
			statusText.width = 500;
			
			statusText.setTextFormat(formatError);
            statusText.x = (stage.stageWidth / 2) - (statusText.width / 2);
        }
        private function addAllQuestions() {
            for(var i:int = 0; i < quizQuestions.length; i++) {
                addChild(quizQuestions[i]);
            }
        }
        private function hideAllQuestions() {
            for(var i:int = 0; i < quizQuestions.length; i++) {
                quizQuestions[i].visible = false;
            }
        }
        private function firstQuestion() {
            currentQuestion = quizQuestions[0];
            currentQuestion.visible = true;
        }
        private function prevHandler(event:MouseEvent) {
            showMessage("");
            if(currentIndex > 0) {
                currentQuestion.visible = false;
                currentIndex--;
                currentQuestion = quizQuestions[currentIndex];
                currentQuestion.visible = true;
            } else {
                showMessage("This is the first question, there are no previous ones.");
				
				
				}
        }
        private function nextHandler(event:MouseEvent) {
            showMessage("");
            if(currentQuestion.userAnswer == 0) {
                showMessage("Please answer the current question before continuing.");
                return;
            }
            if(currentIndex < (quizQuestions.length - 1)) {
                currentQuestion.visible = false;
                currentIndex++;
                currentQuestion = quizQuestions[currentIndex];
                currentQuestion.visible = true;
            } else {
                showMessage("That's all the questions! Click Finish to Score, or Previous to go back.");
            }
        }
        private function finishHandler(event:MouseEvent) {
            showMessage("");
            var finished:Boolean = true;
            for(var i:int = 0; i < quizQuestions.length; i++) {
                if(quizQuestions[i].userAnswer == 0) {
                    finished = false;
                    break;
                }
				
				
            }
            if(finished) {
                prevBtn.visible = false;
                nextBtn.visible = false;
                finishBtn.visible = false;
                hideAllQuestions();
                computeScore();
				
				
            } else {
                showMessage("You haven't answered all of the questions.");
            }
        }
        private function computeScore() {
            for(var i:int = 0; i < quizQuestions.length; i++) {
                if(quizQuestions[i].userAnswer == quizQuestions[i].correctAnswer) {
                    score++;
                }
            }
            showMessage("You answered " + score + " correct out of " + quizQuestions.length + " questions.");
			
			/*sendData();*/
			quizResults();
        }
		
		
			function sendData() {
			var myData:URLRequest = new URLRequest("http://www.alexandervince.com/yahoolive/Quiz/saveScore.php");
			myData.method = URLRequestMethod.POST;
			
			var variables:URLVariables = new URLVariables();
			
			variables.score = score;
			myData.data = variables;
			var loader:URLLoader = new URLLoader();
			loader.dataFormat = URLLoaderDataFormat.VARIABLES;
			loader.addEventListener(Event.COMPLETE, dataSent);
			loader.load(myData);
			
			
		}
		
		
		
			function dataSent(evt:Event) {
			if (evt.target.data.inserted=="Ok") {
				
				
			trace ("You Win");
			
			
		} else {
			trace ("You Loose");
		}
	
		
			}
	
	
	
		public function quizResults() {
			
			
					stage.addChild(top5Fans);
					top5Fans.x = 100;
					top5Fans.y = 80;
					
					
					
					

					stage.addChild(graphBar);
					graphBar.x = 170;
					graphBar.y = 105;
				
				
					
					stage.addChild(bar);
					bar.x = 170;
					bar.y = 150;
					
					
					
					
					stage.addChild(barTwo);
					barTwo.x = 170;
					barTwo.y = 200;
					
					
					
					stage.addChild(barThree);
					barThree.x = 170;
					barThree.y = 250;
					
					
					
					stage.addChild(barFour);
					barFour.x = 170;
					barFour.y = 300;
					
					
					
					stage.addChild(barFive);
					barFive.x = 170;
					barFive.y = 350;
					
					
					/*stage.addChild(sideBar);
					sideBar.x = 125;
					sideBar.y = 85;*/
					
					bar.width=0;
				barTwo.width=0;
				barThree.width=0;
				barFour.width=0;
				barFive.width=0;
					
					
					
					getData();
					
					
					
			
			}		
			
			
			
			
	
					function getData() {
				
				var variables:URLVariables = new URLVariables();
				var varSend:URLRequest = new URLRequest("http://www.alexandervince.com/yahoolive/Quiz/loadScoreTwo.php");
				varSend.method = URLRequestMethod.POST;
				varSend.data = variables;
				var varLoader:URLLoader = new URLLoader;
				varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
				varLoader.addEventListener(Event.COMPLETE, showResults);
				varLoader.load(varSend);
			}
			
			
			
			  function showResults (event:Event): void {
                        
                        if (event.target.data.msg == "OK") {							
                            
				var setPercent:Number = event.target.data.score1;
				var setPercentTwo:Number = event.target.data.score2;
				var setPercentThree:Number = event.target.data.score3;
				var setPercentFour:Number = event.target.data.score4;
				var setPercentFive:Number = event.target.data.score5;
				
				
				
			countryOne = new TextField();
            countryOne.text = event.target.data.team1;
            countryOne.autoSize = TextFieldAutoSize.LEFT;
			countryOne.x = 30;
            countryOne.y = 155;
			countryOne.setTextFormat(formatCountry);
			stage.addChild(countryOne);
			
			/*countryOneScore = new TextField();
            countryOneScore.text = event.target.data.score1;
            countryOneScore.autoSize = TextFieldAutoSize.LEFT;
			countryOneScore.x = 110;
            countryOneScore.y = 102;
			countryOneScore.setTextFormat(formatScore);
			stage.addChild(countryOneScore);*/
			
			
			
			countryTwo = new TextField();
            countryTwo.text = event.target.data.team2;
            countryTwo.autoSize = TextFieldAutoSize.LEFT;
			countryTwo.x = 30;
            countryTwo.y = 205;
			countryTwo.setTextFormat(formatCountry);
			stage.addChild(countryTwo);
			
			
			/*countryTwoScore = new TextField();
            countryTwoScore.text = event.target.data.score2;
            countryTwoScore.autoSize = TextFieldAutoSize.LEFT;
			countryTwoScore.x = 110;
            countryTwoScore.y = 162;
			countryTwoScore.setTextFormat(formatScore);
			stage.addChild(countryTwoScore);*/
			
			countryThree = new TextField();
            countryThree.text = event.target.data.team3;
            countryThree.autoSize = TextFieldAutoSize.LEFT;
			countryThree.x = 30;
            countryThree.y = 255;
			countryThree.setTextFormat(formatCountry);
			stage.addChild(countryThree);
			
			/*countryThreeScore = new TextField();
            countryThreeScore.text = event.target.data.score3;
            countryThreeScore.autoSize = TextFieldAutoSize.LEFT;
			countryThreeScore.x = 110;
            countryThreeScore.y = 222;
			countryThreeScore.setTextFormat(formatScore);
			stage.addChild(countryThreeScore);*/
			
			countryFour = new TextField();
            countryFour.text = event.target.data.team4;
			countryFour.autoSize = TextFieldAutoSize.LEFT;
            countryFour.width = 476.05;
			countryFour.height = 100.00;
			countryFour.x = 30;
            countryFour.y = 305;
			countryFour.setTextFormat(formatCountry);
			stage.addChild(countryFour);
			
			/*countryFourScore = new TextField();
            countryFourScore.text = event.target.data.score4;
            countryFourScore.autoSize = TextFieldAutoSize.LEFT;
			countryFourScore.x = 110;
            countryFourScore.y = 282;
			countryFourScore.setTextFormat(formatScore);
			stage.addChild(countryFourScore);*/
			
			
			
			countryFive = new TextField();
            countryFive.text = event.target.data.team5;
			countryFive.autoSize = TextFieldAutoSize.LEFT;
            countryFive.width = 476.05;
			countryFive.height = 100.00;
			countryFive.x = 30;
            countryFive.y = 355;
			countryFive.setTextFormat(formatCountry);
			stage.addChild(countryFive);
			
				
			/*countryFiveScore = new TextField();
            countryFiveScore.text = event.target.data.score5;
            countryFiveScore.autoSize = TextFieldAutoSize.LEFT;
			countryFiveScore.x = 110;
            countryFiveScore.y = 342;
			countryFiveScore.setTextFormat(formatScore);
			stage.addChild(countryFiveScore);	*/
			
				
				
				setPercentage();
				
				function setPercentage() {
				
				
				
				
				
				Tweener.addTween(bar,{width:(setPercent*400)/32, transition:"easeOutBounce", time:1.5});
				Tweener.addTween(barTwo,{width:(setPercentTwo*400)/32, transition:"easeOutBounce", time:2.4});
				Tweener.addTween(barThree,{width:(setPercentThree*400)/32, transition:"easeOutBounce", time:3.0});
				Tweener.addTween(barFour,{width:(setPercentFour*400)/32, transition:"easeOutBounce", time:2.6});
				Tweener.addTween(barFive,{width:(setPercentFive*400)/32, transition:"easeOutBounce", time:1.8});
				
				
				
	
				
				
			}
							
							
							
								trace(event.target.data.score1);
								trace(event.target.data.team1);
								trace(event.target.data.score2);
								trace(event.target.data.team2);
								trace(event.target.data.score3);
								trace(event.target.data.team3);
								trace(event.target.data.score4);
								trace(event.target.data.team4);
								trace(event.target.data.score5);
								trace(event.target.data.team5);
                              trace("GREAT SUCCESS!");
                        }      else {
                              
                              trace("FAIL");
                              
                        }
                        
                        
                        
                  }
				
			
	
				
	
	}
	
	
	
	
	
	
}




package {
	
	import flash.display.Sprite; 
    import flash.events.MouseEvent;
	import flash.events.*;
	import flash.display.*;
	import flash.net.URLRequest;
	import flash.display.Loader;
	import flash.events.ProgressEvent;
	import flash.net.URLVariables;
	import flash.net.URLLoader;
	import flash.net.URLRequestMethod;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.display.MovieClip;
	import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
	import flash.text.*;
	
	//tweener libraries
	import caurina.transitions.*;
	
	
	
	public class quizResults extends MovieClip {
		
		
		
				private var england:englandText_mc = new englandText_mc();
				
				private var bar:bar_mc = new bar_mc();
				private var barTwo:bar_mc = new bar_mc();
				private var barThree:bar_mc = new bar_mc();
				private var barFour:bar_mc = new bar_mc();
				private var barFive:bar_mc = new bar_mc();
	
				
				private var loadData:URLLoader = new URLLoader();
				private var countryOne:TextField;
				
				private var formatCountry:TextFormat = new TextFormat("Verdana", 18, 0xfecd08);  
			
			
			public function quizResults() {
			
							stage.addChild(england);
							england.x = 200;
							england.y = 200;

					
					
					
					stage.addChild(bar);
					bar.x = 50;
					bar.y = 70;
					
					
					stage.addChild(barTwo);
					barTwo.x = 50;
					barTwo.y = 130;
					
					stage.addChild(barThree);
					barThree.x = 50;
					barThree.y = 180;
					
					stage.addChild(barFour);
					barFour.x = 50;
					barFour.y = 230;
					
					stage.addChild(barFive);
					barFive.x = 50;
					barFive.y = 280;
					
					setPercentage();
					getData();
			
			}		
			
			
			public function setPercentage() {
				
				
				var setPercent:Number = 32;
				var setPercentTwo:Number = 16;
				var setPercentThree:Number = 8;
				var setPercentFour:Number = 4;
				var setPercentFive:Number = 2;
				
				
				bar.width=0;
				barTwo.width=0;
				barThree.width=0;
				barFour.width=0;
				barFive.width=0;
				
				
				Tweener.addTween(bar,{width:(setPercent*200)/32, transition:"easeOutBounce", time:1.5});
				Tweener.addTween(barTwo,{width:(setPercentTwo*200)/32, transition:"easeOutBounce", time:1.5});
				Tweener.addTween(barThree,{width:(setPercentThree*200)/32, transition:"easeOutBounce", time:1.5});
				Tweener.addTween(barFour,{width:(setPercentFour*200)/32, transition:"easeOutBounce", time:1.5});
				Tweener.addTween(barFive,{width:(setPercentFive*200)/32, transition:"easeOutBounce", time:1.5});
				
				
			}
			
			
			
			
			function getData() {
				
				var variables:URLVariables = new URLVariables();
				var varSend:URLRequest = new URLRequest("http://localhost:8888/FlashDev/facebook-version/new/Quiz/loadScoreTwo.php");
				varSend.method = URLRequestMethod.POST;
				varSend.data = variables;
				var varLoader:URLLoader = new URLLoader;
				varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
				varLoader.addEventListener(Event.COMPLETE, showResults);
				varLoader.load(varSend);
			}
			
			
			
			  function showResults (event:Event): void {
                        
                        if (event.target.data.msg == "OK") {							
                            //england.text = event.target.data.score;
								trace(event.target.data.score1);
								trace(event.target.data.team1);
								
								
								var countryOne:TextField;
				
				 var formatCountry:TextFormat = new TextFormat("Verdana", 18, 0xfecd08);  
								countryOne = new TextField();
            countryOne.text = event.target.data.team1;
			
            countryOne.width = 200;
			countryOne.height = 100.00;
			countryOne.x = 10;
            countryOne.y = 100;
			countryOne.setTextFormat(formatCountry);
			stage.addChild(countryOne);
								
								
                              trace("YES ALEX YOU WIN!");
                        }      else {
                              
                              trace("ALEX YOU FAIL AT LIFE");
                              
                        }
                        
                        
                        
                  }
 	


	
				
	
	
	}
	
}

Open in new window

Author

Commented:
sorry the 2nd class is the wrong one oops for get the second package the correct one is as follows
/*Scripted by Alexander Vince for Hijack Media June 2010*/
package {
    import flash.display.Sprite;
	import flash.text.*;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
	import fl.controls.TextArea;
    import flash.events.Event;
    import fl.controls.RadioButton;
    import fl.controls.RadioButtonGroup;
	import flash.events.*;
	import flash.display.*;
	
	
   
    public class QuizQuestion extends MovieClip {
        private var question:String;
        private var questionField:TextField;
        private var choices:Array;
        private var theCorrectAnswer:int;
        private var theUserAnswer:int;
       
        //variables for positioning:
        private var questionX:int = 60;
        private var questionY:int = 130;
        private var answerX:int = 194;
        private var answerY:int = 230;
        private var spacing:int = 30;
		
		
				
		
		
		//text styling
		private var format:TextFormat = new TextFormat("Verdana", 22, 0xffffff);  
		private var formatQuestions:TextFormat = new TextFormat("Verdana", 18, 0xfecd08);  
  
		
		 
		
               
        public function QuizQuestion(theQuestion:String, theAnswer:int, ...answers) {
            //store the supplied arguments in the private variables:
            question = theQuestion;
            theCorrectAnswer = theAnswer;
            choices = answers;
            //create and position the textfield (question):
            questionField = new TextField();
            questionField.text = question;
			questionField.wordWrap = true;
			questionField.multiline = true;
            //questionField.autoSize = TextFieldAutoSize.LEFT;
            questionField.width = 476.05;
			questionField.height = 100.00;
			questionField.x = questionX;
            questionField.y = questionY;
			questionField.setTextFormat(format);
			
			
            addChild(questionField);
			
            //create and position radio buttons (answers):
            var myGroup:RadioButtonGroup = new RadioButtonGroup("group1");
            myGroup.addEventListener(Event.CHANGE, changeHandler);
            for(var i:int = 0; i < choices.length; i++) {
                var rb:RadioButton = new RadioButton();
                rb.textField.autoSize = TextFieldAutoSize.LEFT;
                rb.label = choices[i];
				rb.setStyle("textFormat", formatQuestions);
                rb.group = myGroup;
                rb.value = i + 1;
                rb.x = answerX;
                rb.y = answerY + (i * spacing);
                addChild(rb);
            }
        }
       
        private function changeHandler(event:Event) {
            theUserAnswer = event.target.selectedData;
        }
        public function get correctAnswer():int {
            return theCorrectAnswer;
        }
        public function get userAnswer():int {
            return theUserAnswer;
        }
    }
}

Open in new window

Author

Commented:
I have actually worked out how to do this myself

added a new content loaderinfo listen to run a func called onLoaderInit

loadSwf.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);


Sends it to new swf



function onLoaderInit(e:Event) : void {
                              
                                    Object(loadSwf.content).init(comboBox.selectedLabel);
                              
                        }





child swf recieves and traces value


function init(param:String) :void {
                  
                  trace(param);
                  
                  
                  }



now my next problem trying to turn this into a variable that i can pass to my sendData func. Slowly but surely I will get there. Cheers for your help anyway. If you have any suggestions on my next problem that would be greatly appreciated!

Author

Commented:
Solved it

set a var at top of class                              var country:String;



function init(param:String) :void {
                  
                  trace(param);
                  
//Then set the var here

                  country = param;
                  
                  trace(country);
                  
                  
                  
                  }



Author

Commented:
Helped me figure it all out!
Congrats!! you made it work!!

Commented:
Maybe this has something to do, if a remove the cast like

connectorLoader.content

instead of

(connectorLoader.content as Connector)

I get in the console [class Connector]

but if I change the cast to

Connector(connectorLoader.content)

it said

TypeError: Error #1034: Type Coercion failed: cannot convert com.goseta::Connector@2a8890b1 to com.goseta.Connector.
      at com.goseta::HostMain/onConnectorLoaded()

which mean is trying to convert to a different class, but is the same one, what I'm doing wrong, please help me!!, thanks! :(