Copy link to clipboard
Copied
Hello. I have simple txt file:
Where is Eiffel tower?;paris
King of music instruments?;organs
What is my name?;harry potter
I want that flash random select the question and upload to question dynamic text field "question"
But for answer I have biggest task.
In library I have movie clips with names a; b;c;d;e;f;g;....
After question i want that flash uploads the movie clip in line:
For example question Where is Eiffel tower?
Answer PARIS
Flash in one line uploads movie with name "p" "a" "r" "i" "s"
Maby someone have some ideas? How script have to look? Sorry I new in AS3 but i think i will learn. i study every script i got to know how it works;) thanks for your help
the last error (about line 4, answer) is not in my code.
for the rest, that should be:
...
kglad wrote:
i assumed you were going to use a separate answers.txt with the nth line being the answer to question n. if that's the case your code is setup to handle that:
//////////////////////////////// being frame 1 code /////////////////////
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("questions.txt"));
myLoader.addEventListener(Event.COMPLETE, questionsLoaded);
var quest
Copy link to clipboard
Copied
google a multiple choice tutorial. adding randomness is easy.
Copy link to clipboard
Copied
I just see tutorials for Quiz with interactive textfields with mouse.event for correct and wrong answers. I have questions just with one correct answer.
Simple text loading from file to dynamic text field:
var loader:URLLoader = new URLLoader(new URLRequest("questions.txt"));
loader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:Event):void {
var loadedText:URLLoader = URLLoader(event.target);
question.text = loadedText.data;
}
But problem is that I see always first line in text field and answer too. Me need that flash every time randomly select the line and give it to text field without answer wich is seperated with ";". And dont repeat the question until i close the flash.
Text file:
Where is Eiffel tower?;paris
King of music instruments?;organs
What is my name?;harry potter
Every time i see the result in dynamic text field:
Where is Eiffel tower?;paris
Much bigger problem for me here with answers. In all tutorials I find just upload some wrong answers and one correct answer in interactive (mouse.event) text fields. I have to click on linne and I see if i select good or wrong. I DONT NEED THIS.
This is that I want to do. I see question after question I see answer. In my flash library I have all alphabet of movie clips. With letters names from A-Z. I have keyboard.event for every movie object with letters. Then on keyboard I press A the movie clip with name "A" plays (if in answer is letter A then flash opens the letter) and stops...But with keyboard events everything is fine.
Me need that flash selects randomly question from txt file for example:
What is my name?/THOMAS
In text field question I see "What is my name?"
After that in one line I want to se answer from diferent movieclips.
"T" upload in frame movie object clip with name "T"
"H" upload in frame movie object clip with name "H"
"O" upload in frame movie object clip with name "O"
and so on....
In these movieclips no text fields its just movie clips.
(for this I think need use IF and reapeat until he finish the answer.)
I think this is big job for that. In first frame I think need write all script. In others just give a comand to do that script.
Me need a script for example one letter.. for all alphabet I do myself. But now Im not imagine how to do that.
SORRY FOR MY ENGLISH.
I serch all inthernet and I cant find tutorials or examples for that I want to do.
Copy link to clipboard
Copied
I found another script for loading text from diferent lines. But it works one time then upload the flash file. In second frame dynamic text field is empty. or then i make a movie clip object field is not empty but always shows same text.
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("questions.txt"));
myLoader.addEventListener(Event.COMPLETE, aLoaded);
var aArray:Array = new Array();
var aContent:String
var aSplit:String;
function aLoaded(event:Event):void {
aContent = event.target.data;
aArray = aContent.split("\n");
output.text = aArray[Math.floor(Math.random()*aArray.length)];
}
I still dont undertand how theese scripts working...
Copy link to clipboard
Copied
i'm not sure that's going to do what you want because you're going to see repeat questions.
anyway, in your next frame, do not reload questions.txt. just use:
output.text = aArray[Math.floor(Math.random()*aArray.length)];
Copy link to clipboard
Copied
i don't know how you calculated a 5/10 chance of a repeat, but make sure there are 10 different questions in question.txt.
then in your first frame use:
//////////////////////////////// being frame 1 code /////////////////////
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("questions.txt"));
myLoader.addEventListener(Event.COMPLETE, aLoaded);
var aArray:Array = new Array();
var randomArray:Array = [];
var index:int = 0;
var aContent:String
var aSplit:String;
function aLoaded(event:Event):void {
aContent = event.target.data;
aArray = aContent.split("\n");
for(var i:int=0;i<aArray.length;i++){
randomArray.push(i);
}
shuffle(randomArray);
output.text = aArray[randomArray[index]];
}
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
;
a
= t;
}
}
/////////////////////////// end frame 1 code ////////////////////////////////////
//in the keyframes for subsequent questions put:
///////////// begin subsequent frame code /////////////////////////////////////
index++;
output.text = aArray[randomArray[index]];
///////////// end subsequent frame code /////////////////////////////////////
Copy link to clipboard
Copied
That scipt is not good for me i understand. Because the questions repeats...
I already write what i want to do but i just dont know the way how to do it.
Copy link to clipboard
Copied
first get it working with repeat questions, then i'll show you how to prevent repeats.
Copy link to clipboard
Copied
That script works just repeats the questions and in one line I see What is my name?/Thomas
Copy link to clipboard
Copied
you made a text file (questions.txt) with about 10 questions?
and when you display the first question, it shows without problem?
when you display the second question, it shows without problem (though there's a 1/10 chance it will be the same as the first question)?
Copy link to clipboard
Copied
Fore example 10 questions in txt and 10 keyframes sometimes in next frame I see the same question like before. This is more than 5/10 chance that in next frame will be the same question.
Copy link to clipboard
Copied
If in the text file will be more questions than 10.. for example 23 it works?
Copy link to clipboard
Copied
yes.
test it.
Copy link to clipboard
Copied
Oh it works good I did`t expect that script is so big and dificult for that simple thing:|
One step forward Nice.
Next step to seperate answer after "/"
Because now i see:
What is your name?/Thomas
I think this is something about string.toSplit method.
Copy link to clipboard
Copied
i assumed you were going to use a separate answers.txt with the nth line being the answer to question n. if that's the case your code is setup to handle that:
//////////////////////////////// being frame 1 code /////////////////////
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("questions.txt"));
myLoader.addEventListener(Event.COMPLETE, questionLoaded);
var questionsArray:Array = new Array();
var answersArray:Array = [];
var randomArray:Array = [];
var index:int = 0;
var aContent:String
var aSplit:String;
function questionsLoaded(event:Event):void {
myLoader.removeEventListener(Event.COMPLETE, questionLoaded);
myLoader.addEventListener(Event.COMPLETE, answerLoaded);
myLoader.load(new URLRequest("answers.txt"));
aContent = event.target.data;
questionsArray = aContent.split("\n");
for(var i:int=0;i<aArray.length;i++){
randomArray.push(i);
}
shuffle(randomArray);
output.text = questionsArray[randomArray[index]];
// the answer to this question will be answersArray[randomArray[index]];
}
function answersLoaded(event:Event):void {
aContent = event.target.data;
answersArray = aContent.split("\n");
}
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
;
a
= t;
}
}
/////////////////////////// end frame 1 code ////////////////////////////////////
//in the keyframes for subsequent questions put:
///////////// begin subsequent frame code /////////////////////////////////////
index++;
output.text = questionsArray[randomArray[index]];
// the answer to this question is answersArray[randomArray[index]];
///////////// end subsequent frame code /////////////////////////////////////
Copy link to clipboard
Copied
the last error (about line 4, answer) is not in my code.
for the rest, that should be:
kglad wrote:
i assumed you were going to use a separate answers.txt with the nth line being the answer to question n. if that's the case your code is setup to handle that:
//////////////////////////////// being frame 1 code /////////////////////
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("questions.txt"));
myLoader.addEventListener(Event.COMPLETE, questionsLoaded);
var questionsArray:Array = new Array();
var answersArray:Array = [];
var randomArray:Array = [];
var index:int = 0;
var aContent:String
var aSplit:String;
function questionsLoaded(event:Event):void {
myLoader.removeEventListener(Event.COMPLETE, questionsLoaded);
myLoader.addEventListener(Event.COMPLETE, answersLoaded);
myLoader.load(new URLRequest("answers.txt"));
aContent = event.target.data;
questionsArray = aContent.split("\n");
for(var i:int=0;i<questionsArray.length;i++){
randomArray.push(i);
}
shuffle(randomArray);
output.text = questionsArray[randomArray[index]];
// the answer to this question will be answersArray[randomArray[index]];
}
function answersLoaded(event:Event):void {
aContent = event.target.data;
answersArray = aContent.split("\n");
}
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
;
a
= t;
}
}
/////////////////////////// end frame 1 code ////////////////////////////////////
//in the keyframes for subsequent questions put:
///////////// begin subsequent frame code /////////////////////////////////////
index++;
output.text = questionsArray[randomArray[index]];
// the answer to this question is answersArray[randomArray[index]];
///////////// end subsequent frame code /////////////////////////////////////
and you can use one file but, if you do that, you should use an xml and not a text file.
Copy link to clipboard
Copied
If i use xml this script is bad?
Copy link to clipboard
Copied
If for xml file everything need to change this is a hard job. Then I leave 2 txt files questions.txt and answers.txt . This script is working for me and thats good.
But now I think will be hardest job:
If I have anwer for example THOMAS
For every letter I need to upload move object in keyframe center in one line.
Letter "T" upload movie object clip in keyframe with name "T"
Letter "H" ...........................................................with name "H"
Letter "O" ...........................................................with name "O"
Letter "M" ...........................................................with name "M"
Letter "A" ............................................................with name "A"
Letter "S" ............................................................with name "S"
Every object have names "A", "B", "C", "D", "E",...."W", "X", "V", "Z". Every object is 150px X 150px. Spaces between movies about 15px. Avery object Export for ActionScript.
150px 15px 150 px 15px 150 px 15px 150 px 15px 150 px 15px 150 px
| T | | H | | O | | M | | A | | S |
addChild have one problem after adding the movies dont play. Me need to play because then i press key "T" the movie with name "T" have to play.
Copy link to clipboard
Copied
the script need to change if you use xml, but that's not much more difficult than putting the questions and answers in one text file and has the advantage of being easier to understand and maintain.
do you have 26 movieclips (with class names A,B,etc)? or do you have one movieclip with 26 keyframes and in each keyframe there is a movieclip with instance name A,B,etc?
Copy link to clipboard
Copied
I have 35 different clips (with class names a, b, c, d, etc:)
I have 35 becouse of Lithuanian (Baltic) letters (I mean ĄČĘĖĮŠŲŪŽ) and I think this is not that simple with these Letters or Im wrong?
Copy link to clipboard
Copied
if you have classes A,B,C etc you can use
function answerF(answerS:String,x:int,y:int,space:int):void{
var nextX:int = x;
var C:Class;
var letter:MovieClip;
for(var i:int=0;i<answerS.length;i++){
C=Class(getDefinitionByName(answerS.charAt(i)));
letter=new C();
addChild(letter);
letter.x=nextX;
letter.y=y;
nextX=letter.width+space;
}
}
Copy link to clipboard
Copied
his is script for all answers? hm i dont understand really:|
Copy link to clipboard
Copied
This script works together with that first one with questions and answers?
Copy link to clipboard
Copied
yes. it solves a different problem you asked about placing movieclips on the stage.
but you're original question has been answered and you should make helpful and correct answers.
Copy link to clipboard
Copied
With random questions all works fine im happy with that. Thanks.
Just answers I still have just on text field.
With last script I dont know what to do and where is a place for that script. I have to change something in that script or that script should work?
Sorry for my bothering but I try to finnish my 4 week headache. Im green in as3, but I try to undersand these all scripts how they work and etc. Just at the momment it is hard for me.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now