A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: How to randomly spawn 3 out of 10 questions from library? AS3

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    2

    How to randomly spawn 3 out of 10 questions from library? AS3

    So i'm really new at flash and i'm having some trouble with a textbook assignment.
    Before i explain my problem here is the code:


    Code:
    stop();
    
    var defValue:Number = 1;
    
    
    stage.addEventListener(Event.ENTER_FRAME, vetIkke);
    
    function vetIkke(e:Event){
    	while (defValue < 3){
    		defValue ++;
    	        var randomTall = Math.floor((Math.random()*10)+1);
                    var randomQ:String = "question" + randomTall;
    		var Question:MovieClip = new randomQ();
    		Question.x = 53;
    		Question.y = defValue*83;
    		addChild(Question);
    	}
    }
    I was doing some assignments in my as3 textbook when i ran into a bit of trouble. I'm trying to make a flash that picks 3 random questions out of a total of 10 and displays them on screen. I made each of the questions movieclips and assigned them all a class (question1 - 10) through Linkage. So the variable "randomQ" is the name of the class of a random question, but how do i get flash to understand that? And how do i spawn that question as a movieclip on stage?
    I'm guessing it has something to do with this line of code:
    Code:
    var Question:MovieClip = new randomQ();
    I've tried various alterations but can't seem to find the right one. It's possible i've yet to learn the neccesary knowledge in order to make this flash, and in that case i really need all the help i can get. What is wrong and why isn't flash creating the movieclips i want it to?

    Any help is really appreciated!

  2. #2
    Junior Member
    Join Date
    Feb 2010
    Posts
    2
    I realize now a better title might have been, "How do I spawn random movieclips from classes on stage" or "Can't convert string variable to movieclip variable" or something like that.

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