A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: click button and then go to a random scene.

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    2

    click button and then go to a random scene.

    I am creating a quiz in Flash using Actionscript 3.0

    I need the questions to appear randomly, each time the application is used. The questions are in a different order.

    Also the application cannot go back to the first scene as that is a start page.

    I am not terribly sure how to do this.

    stop();

    BTstart.addEventListener(MouseEvent.CL… clickFunction);

    function clickFunction(evt:MouseEvent):void
    {
    gotoAndStop("start 1","Question 1");
    }

    this is the code for the button

    Thanks in advance.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I have no idea why you'd use scenes for this, but what you can do is put all your eligible scene names in an array, and choose the next scene from the array then remove it.

    So something like:
    Code:
    var scenenames:Array = ["Question 1", "Tom", "Sue", "Harry", "foo"];
    
    function getRandomScene():String{
      var i:int = Math.floor(Math.random()*scenenames.length);
      var scenename:String = scenenames[i];
      scenenames.splice(i, 1); //remove that one.
      return scenename;
    }
    And in your gotoAndStop line you can call getRandomScene instead.
    Code:
    gotoAndStop("start 1", getRandomScene());

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