• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

I can't next to frame

Community Beginner ,
Sep 05, 2024 Sep 05, 2024

Copy link to clipboard

Copied

Hello i'm new in Adobe Animate , I wanna make a quiz multiple choice , I want my quizzes to be random when they start and when they repeat. So I try to make the question randomly 

I'm use 3 frame 

1. Button Start 
2. Frame with Movie Clip (There is , Dynamic Text and Answer Button)
3. Dynamic Text for Score and Repeat Button

when i'm insert the code in frame 1 to next to frame 2 (A movie clip) it's not working
here the code : 

//variabel global
var data = [{
	pertanyaan_text: "1+1",
	jawaban: "2",
	jawabann: ["1", "3", "2"]
}, {
	pertanyaan_text: "Berapa Jumlah hari dalam Seminggu",
	jawaban: "1",
	jawabann: ["5", "7", "8"]
}, {
	pertanyaan_text: "Bumi Merupakan Planet Ke-",
	jawaban: "0",
	jawabann: ["4", "5", "8"]
}, ];

var indexPertanyaan = 0;
var currentPertanyaan;

this.bt_quis.addEventListener(MouseEvent.CLICK, function(){
//Sembunyikan tombol mulai, tampilkan movie clip pertanyaan
consol.log("Button Clicked");
btn_quis.visible = false;
mc_kuis.visible = true;

//load the first question
loadPertanyaan();

});

mc_kuis is the instance name for the movie clip in frame 2
loadPertanyaan is the function tu load the question to dynamic text in Movie Clip in frame 2

In frame 2 here the code I use :

function loadPertanyaan(){

//Acak Soal
data= mixed(data);
	
//Ambil soal pertama yang baru
currentPertanyaan = data[indexPertanyaan];
	
//Tampilkan pertanyaan
mc_kuis.txt_Pertanyaan.text = currentPertanyaan.pertanyaan_text;
	
}

 

I've to use consol.log() at the button bt_quis but it's not working 
and I wanted to ask if it's possible to take a global variable in frame 1 to use in frame 2.?
Thanks for the help 

Views

171

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 06, 2024 Sep 06, 2024

use the fisher-yates shuffle method:

 

function shuffle(a:Array) {
var p:int;
var t:*;
var ivar:int;
for (ivar = a.length-1; ivar>=0; ivar--) {
p=Math.floor((ivar+1)*Math.random());
t = a[ivar];
a[ivar] = a[p];
a[p] = t;
}
}

Votes

Translate

Translate
Community Expert ,
Sep 06, 2024 Sep 06, 2024

Copy link to clipboard

Copied

use the fisher-yates shuffle method:

 

function shuffle(a:Array) {
var p:int;
var t:*;
var ivar:int;
for (ivar = a.length-1; ivar>=0; ivar--) {
p=Math.floor((ivar+1)*Math.random());
t = a[ivar];
a[ivar] = a[p];
a[p] = t;
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 06, 2024 Sep 06, 2024

Copy link to clipboard

Copied

Thank!
Here's how I currently have it on frame 2.

function mixed(Items)
{
	var newArray=[];
	var original= Items.concat();
	while(original.length>0)
	{
	  var r =Math.floor(Math.random()*(original.length));
		newArray.push(original[r]);
		original.splice(r,1);
	}
	return newArray;
}

loadPertanyaan.bind(this)();

function loadPertanyaan(){
//Acak Soal
data= mixed(data);
	
//Ambil soal pertama yang baru
currentPertanyaan = data[indexPertanyaan];
	
//Tampilkan pertanyaan
this.mc_kuis.txt_Pertanyaan.text = currentPertanyaan.pertanyaan_text;
	
//Acak pilihan jawaban dan menampilkan pada button
var acakJawaban = mixed(currentPertanyaan.pilihan_jawaban);
this.mc_kuis.bt_jawaban1.txt_Jawaban.text = acakJawaban[0];
this.mc_kuis.bt_jawaban2.txt_Jawaban.text = acakJawaban[1];
this.mc_kuis.bt_jawaban3.txt_Jawaban.text = acakJawaban[2];
this.mc_kuis.bt_jawaban4.txt_Jawaban.text = acakJawaban[3];
}

Functionally it works, The Question and the Answer are randomizing .
But Now When choose the answer, the next question not load 
here code I use :

this.mc_kuis.bt_jawaban1.on("click",onClickAnswer.bind(this));
this.mc_kuis.bt_jawaban2.on("click",onClickAnswer.bind(this));
this.mc_kuis.bt_jawaban3.on("click",onClickAnswer.bind(this));
this.mc_kuis.bt_jawaban4.on("click",onClickAnswer.bind(this));

function onClickAnswer(e)
{
if(IsAnswer==false)
	{
		var item=e.currentTarget;
		if(item.name=="jawaban_benar"+currentPertanyaan.jawaban)
		{
			skor+=10;
		}else{
			skor+=0;
		}
		IsAnswer=true;
	}
	NextQuestion();
	console.log(loadPertanyaan);
}

function NextQuestion()
{
	indexPertanyaan++;
	if(indexPertanyaan==data.length)
	{
		this.gotoAndStop("LB_Hasil");
	}else{
		currentPertanyaa=data[indexPertanyaan];
		IsAnswer=false;
		loadPertanyaan.bind(this)();
	}
}

 

Here the error when I click the button answer 

Screenshot 2024-09-06 221353.png



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 06, 2024 Sep 06, 2024

Copy link to clipboard

Copied

there's no such textfield (txt_per...)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 06, 2024 Sep 06, 2024

Copy link to clipboard

Copied

It's a instance name of the dynamic text for question.
Now it's solve , I'm forgot to write bind(this) in function NextQuestion();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 06, 2024 Sep 06, 2024

Copy link to clipboard

Copied

i thought you were using as3 in a duplicate post.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 06, 2024 Sep 06, 2024

Copy link to clipboard

Copied

I use a html5 canvas for this 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 06, 2024 Sep 06, 2024

Copy link to clipboard

Copied

LATEST

ok

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines