A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: quiz score system!

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    7

    quiz score system!

    Hi there,

    I have a huge problem and I really could have some help to figure this out. I'm trying to do a "complex" quiz game.

    To make it simple: The quiz is divided into 8 questions. Each question is a swf file that is going to be loaded into other swf that needs to "holde" some variables. At the end of each question, the code creates a set of numbers for a group of specific variables . like this exemple:


    swf question 1
    Actionscript Code:
    ActionScript Code:
    ---------------------------------

    var place1:Number;
    var place2:Number;
    var place3:Number;
    var place4:Number;
    var place5:Number;
    var place6:Number;



    bt1.addEventListener (MouseEvent.CLICK, answer1);
    bt2.addEventListener (MouseEvent.CLICK, answer2);


    function answer1 (evtObj:MouseEvent)
    {
       place1 = 2;
       place2 = 2;
       place3 = 0;
       place4 = 1;
       place5= 1;
       place6 = 1;    
    }

    function answer2 (evtObj:MouseEvent)
    {
       place1 = 1;
       place2 = 1;
       place3 = 1;
       place4 = 0;
       place5= 0;
       place6 = 0;    
    }



    swf question 2
    Actionscript Code:
    ---------------------------------

    var place1:Number;
    var place2:Number;
    var place3:Number;
    var place4:Number;
    var place5:Number;
    var place6:Number;



    bt1.addEventListener (MouseEvent.CLICK, answer1);
    bt2.addEventListener (MouseEvent.CLICK, answer2);


    function answer1 (evtObj:MouseEvent)
    {
       place1 = 2;
       place2 = 1;
       place3 = 2;
       place4 = 1;
       place5= 1;
       place6 = 2;    
    }

    function answer2 (evtObj:MouseEvent)
    {
       place1 = 1;
       place2 = 2;
       place3 = 2;
       place4 = 1;
       place5= 0;
       place6 = 2;    
    }



    How I pass those variables (place1, place2,place3...) to my swf holder.

    How can I sum the numbers created for each "place" in the swf holder. something like this:
    At the end of question1, place1 has 2 points, at end of question2 it has 4....


    Sorry about the english, my mother language is Portuguese.


    An thanks for the help!

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    stop();
    var questionbox:MovieClip = new MovieClip();
    questionbox.x=10;
    questionbox.y=10;
    this.addChild(questionbox);
    questionbox.place1=0;
    questionbox.place2=0;
    questionbox.place3=0;
    questionbox.place4=0;
    questionbox.place5=0;
    questionbox.place6=0;
    
    var myLoad:Loader = new Loader();
    questionbox.addChild(myLoad);
    
    var counter:uint=0;
    var qArray:Array=["question1","question2","question3"];
    var points:Array=new Array(qArray.length);
    var myMC:MovieClip=null;
    var isLoaded:Boolean=false;
    
    prev_btn.addEventListener(MouseEvent.CLICK, goPrev);
    next_btn.addEventListener(MouseEvent.CLICK, goNext);
    
    function goPrev(e:MouseEvent):void {
    	removeSWF(e);
    	counter = (--counter < 0)? 0 : counter;
    	loadSWF(e);
    	trace("c :"+counter);
    }
    function goNext(e:MouseEvent):void {
    	removeSWF(e);
    	counter = (++counter > qArray.length-1)? qArray.length-1 : counter;
    	loadSWF(e);
    	trace("c :"+counter);
    }
    
    function completeHandler(e:Event):void {
    	if (e.target.content is MovieClip) {
    		isLoaded=true;
    		myMC=MovieClip(e.currentTarget.content);
    		if (points[counter]!=undefined) {
    			myMC.place1=points[counter][0];
    			myMC.place2=points[counter][1];
    			myMC.place3=points[counter][2];
    			myMC.place4=points[counter][3];
    			myMC.place5=points[counter][4];
    			myMC.place6=points[counter][5];
    		}
    	}
    }
    
    function loadSWF(e:MouseEvent=null):void {
    	isLoaded=false;
    	myLoad.load(new URLRequest(qArray[counter]+".swf"));
    	myLoad.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
    }
    
    function removeSWF(e:MouseEvent):void {
    	if (isLoaded) {
    		points[counter]=[myMC.place1,myMC.place2,myMC.place3,myMC.place4,myMC.place5,myMC.place6];
    	}
    	trace(points);
    	totalPlaces();
    	myLoad.unloadAndStop();
    }
    function totalPlaces() {
    	for (var i in qArray) {
    		if (points[i]!=undefined) {
    			for (var j in points[i]) {
    				if (! isNaN(points[i][j])) {
    					questionbox["place"+(j+1)] += points[i][j];
    				}
    			}
    		}
    	}
    	trace("TOTALS");
    	trace("place1 :"+questionbox.place1);
    	trace("place2 :"+questionbox.place2);
    	trace("place3 :"+questionbox.place3);
    	trace("place4 :"+questionbox.place4);
    	trace("place5 :"+questionbox.place5);
    	trace("place6 :"+questionbox.place6);
    	trace("***");
    }
    loadSWF();

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    7
    thank you so much, I'm learning a lot with this code.

    but, just one thing...
    When i click the goNext.btn

    It traces this :
    Actionscript Code:
    2,2,2,1,1,1,,
    TOTALS
    Place1 :0
    Place2 :0
    Place3 :0
    Place4 :0
    Place5 :0
    Place6 :0
    ***
    c :1

    If I go to second question for example, it traces this:

    Actionscript Code:
    2,2,2,1,1,1,,
    TOTALS
    Place1 :0
    Place2 :0
    Place3 :0
    Place4 :0
    Place5 :0
    Place6 :0
    ***
    c :1
    2,2,2,1,1,1,5,0,0,0,2,0,
    TOTALS
    Place1 :0
    Place2 :0
    Place3 :0
    Place4 :0
    Place5 :0
    Place6 :0
    ***
    c :2

    It is not summing the places point
    I'm not sure what I'm doing wrong.

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Can you post your fla?

  5. #5
    Junior Member
    Join Date
    Apr 2010
    Posts
    7
    OH God....it is working!
    I made a mistake when I change the variable names.

    Thanks a million for the big help!

  6. #6
    Junior Member
    Join Date
    Apr 2010
    Posts
    7
    Hi there,
    sorry for bothering you again!
    Everything is almost working


    The only problem, is that the prev_btn should subtract the latest value and not add them!

    Can you pls help me out in this!

    Plz, find attached the Fla that is loading the swfs files.
    Attached Files Attached Files

  7. #7
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    var questionbox:MovieClip = new MovieClip();
    questionbox.x=10;
    questionbox.y=10;
    this.addChild(questionbox);
    
    questionbox.Place1=0;
    questionbox.Place2=0;
    questionbox.Place3=0;
    questionbox.Place4=0;
    questionbox.Place5=0;
    questionbox.Place6=0;
    
    var myLoad:Loader = new Loader();
    questionbox.addChild(myLoad);
    
    var counter:uint=0;
    
    var qArray:Array=["question1","question2","question3"];
    var points:Array=new Array(qArray.length);
    var myMC:MovieClip=null;
    var isLoaded:Boolean=false;
    
    next.addEventListener(MouseEvent.CLICK, goPrev);
    back.addEventListener(MouseEvent.CLICK, goNext);
    
    function goPrev(e:MouseEvent):void {
    	removeSWF(e);
    	counter = (--counter < 0)? 0 : counter;
    	loadSWF(e);
    	trace("c :"+counter);
    }
    function goNext(e:MouseEvent):void {
    	removeSWF(e);
    	counter = (++counter > qArray.length-1)? qArray.length-1 : counter;
    	loadSWF(e);
    	trace("c :"+counter);
    }
    
    function completeHandler(e:Event):void {
    	if (e.target.content is MovieClip) {
    		isLoaded=true;
    		myMC=MovieClip(e.currentTarget.content);
    		if (points[counter]!=undefined) {
    			myMC.Place1=points[counter][0];
    			myMC.Place2=points[counter][1];
    			myMC.Place3=points[counter][2];
    			myMC.Place4=points[counter][3];
    			myMC.Place5=points[counter][4];
    			myMC.Place6=points[counter][5];
    		}
    		totalPlaces();
    	}
    }
    
    function loadSWF(e:MouseEvent=null):void {
    	isLoaded=false;
    	myLoad.load(new URLRequest(qArray[counter]+".swf"));
    	myLoad.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
    }
    
    function removeSWF(e:MouseEvent):void {
    	if (isLoaded) {
    		points[counter]=[myMC.Place1,myMC.Place2,myMC.Place3,myMC.Place4,myMC.Place5,myMC.Place6];
    	}
    	trace(points);
    	totalPlaces();
    	myLoad.unloadAndStop();
    }
    function totalPlaces() {
    	questionbox.Place1=0;
    	questionbox.Place2=0;
    	questionbox.Place3=0;
    	questionbox.Place4=0;
    	questionbox.Place5=0;
    	questionbox.Place6=0;
    	for (var i in qArray) {
    		if (i>counter) {
    			break;
    		} else if (points[i]!=undefined) {
    			for (var j in points[i]) {
    				if (! isNaN(points[i][j])) {
    					var val:String = "Place"+(j+1);
    					questionbox[val]+=points[i][j];
    				}
    			}
    		}
    	}
    	trace("TOTALS");
    	trace("Place1 :"+questionbox.Place1);
    	trace("Place2 :"+questionbox.Place2);
    	trace("Place3 :"+questionbox.Place3);
    	trace("Place4 :"+questionbox.Place4);
    	trace("Place5 :"+questionbox.Place5);
    	trace("Place6 :"+questionbox.Place6);
    	trace("***");
    }
    loadSWF();

  8. #8
    Junior Member
    Join Date
    Apr 2010
    Posts
    7
    Pls, take a look in these file. I made a small scale example of the project.
    I think it will be easier understand what is going wrong.

    thanks again for your patient.
    Attached Files Attached Files

  9. #9
    :
    Join Date
    Dec 2002
    Posts
    3,518
    ??
    Code:
    //next.addEventListener(MouseEvent.CLICK, goPrev);
    //back.addEventListener(MouseEvent.CLICK, goNext);
    back.addEventListener(MouseEvent.CLICK, goPrev);
    next.addEventListener(MouseEvent.CLICK, goNext);

  10. #10
    Junior Member
    Join Date
    Apr 2010
    Posts
    7
    Oh god, what a stupid error.
    I think every thing is working fine right now!

    You spared hundreds hours of headache. I really appreciate it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center