-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathApacheQuiz.mxml
419 lines (377 loc) · 16.8 KB
/
ApacheQuiz.mxml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 Justin Mclean
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<js:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:js="library://ns.apache.org/royale/basic"
xmlns:html="library://ns.apache.org/royale/html"
applicationComplete="loadQuiz()">
<fx:Script><![CDATA[
import org.apache.royale.events.Event;
import org.apache.royale.net.HTTPConstants;
import org.apache.royale.net.HTTPService;
import org.apache.royale.html.CheckBox;
import org.apache.royale.html.elements.A;
public const NO_CHECKBOXES:int = 8;
public const NO_HINTS:int = 8;
public const NO_LINKS:int = 8;
public var load:HTTPService = new HTTPService();
public var questions:Array = [];
[Bindable] public var score:Number;
[Bindable] public var total:int;
[Bindable] public var maxQuestions:int;
[Bindable] public var noQuestions:int = 5;
public var questionNo:int;
public var order:Array = [];
public var level:int = 1;
[Bindable] public var right:Boolean;
[Bindable] public var ask:String;
[Bindable] public var reason:String;
[Bindable] public var link:String;
[Bindable] public var noright:int = 0;
public var actualShown:int;
public function loadQuiz():void {
load.url = "quiz.json";
load.addEventListener("complete", loadedJSON);
load.send();
}
public function loadedJSON(event:Event):void {
questions = load.json as Array;
maxQuestions = questions.length;
}
public function chooseQuestion():void {
questionNo = Math.floor(Math.random()*maxQuestions);
var question:Object = questions[questionNo];
ask = question["question"];
var showNo:int = question["show"];
var answers:Array = question["answers"];
var noAnswers:int = answers.length;
for (var i:int = 1; i <= NO_CHECKBOXES; i ++) {
var checkBox:CheckBox = this["checkbox" + i] as CheckBox;
checkBox.visible = false;
}
var checkboxNo:int = 1;
order = [];
var tries:int = 0;
actualShown = 0;
while (actualShown < showNo && tries < 100) {
checkBox = this["checkbox" + checkboxNo] as CheckBox;
var answerNo:int = Math.floor(Math.random() * noAnswers);
if (!order.includes(answerNo) && answers[answerNo]["level"] <= level) {
checkBox.text = answers[answerNo]["answer"];
checkBox.visible = true;
order.push(answerNo);
checkboxNo++;
actualShown++;
}
tries++;
}
}
public function resetCheckboxes():void {
for (var i:int = 1; i <= NO_CHECKBOXES; i++) {
var checkBox:CheckBox = this["checkbox" + i] as CheckBox;
checkBox.selected = false;
checkBox.visible = false;
checkBox.text = "";
}
}
public function hideHints():void {
questionAgain.visible = false;
for (var i:int = 1; i <= NO_HINTS; i++) {
var hint:Label = this["hint" + i] as Label;
var answer:CheckBox = this["answer" + i] as CheckBox;
hint.visible = false;
answer.visible = false;
}
}
public function hideLinks():void {
seealso.visible = false;
for (var i:int = 1; i <= NO_LINKS; i++) {
var link:A = this["link" + i] as A;
link.visible = false;
}
}
public function checkAnswer():Boolean {
var question:Object = questions[questionNo];
var hints:Array = [];
var index:Array = [];
right = true;
noright = 0;
for (var i:int = 1; i <= actualShown; i++) {
var checkbox:CheckBox = this["checkbox" + i] as CheckBox;
var id:int = order[i-1];
var answer:Object = question["answers"][id];
if (checkbox.selected) {
if (!answer["correct"]) {
right = false;
hints.push(answer["hint"]);
index.push(id);
}
else {
// harder questions are worth more
noright += answer["level"];
}
}
else {
if (answer["correct"]) {
right = false;
hints.push(answer["hint"]);
index.push(id);
}
else {
noright++;
}
}
}
noright = noright * 100 / actualShown;
total++;
score += noright/100;
reason = question.reason;
hideHints();
if (hints.length > 0) {
questionAgain.visible = true;
questionAgain.text = question["question"];
for (i = 1; i <= hints.length; i++) {
var hint:Label = this["hint" + i] as Label;
var wrong:CheckBox = this["answer" + i] as CheckBox;
answer = question["answers"][index[i - 1]];
wrong.visible = true;
wrong.text = answer["answer"];
wrong.selected = !answer["correct"];
hint.visible = true;
hint.text = answer["hint"];
}
}
var links:Array = question["links"];
hideLinks();
if (links.length > 0) {
seealso.visible = true;
for (i = 1; i <= links.length; i++) {
var link:A = this["link" + i] as A;
link.visible = true;
link.text = links[i-1]["name"];
link.href = links[i-1]["link"];
}
}
resetCheckboxes();
return right;
}
public function endQuiz():void {
if (total >= noQuestions) {
score = Math.round(score * 10) / 10;
end();
}
else {
question();
}
}
public function reset():void {
score = 0;
total = 0;
}
public function begin():void {
if (noQuestions > 0) {
reset();
question();
}
}
public function settings():void {
startPage.visible = true;
questionPage.visible = false;
resultPage.visible = false;
scorePage.visible = false;
}
public function question():void {
chooseQuestion();
startPage.visible = false;
questionPage.visible = true;
resultPage.visible = false;
scorePage.visible = false;
}
public function result():void {
checkAnswer();
startPage.visible = false;
questionPage.visible = false;
resultPage.visible = true;
scorePage.visible = false;
}
public function end():void {
startPage.visible = false;
questionPage.visible = false;
resultPage.visible = false;
scorePage.visible = true;
}
]]></fx:Script>
<js:valuesImpl>
<js:SimpleCSSValuesImpl/>
</js:valuesImpl>
<js:beads>
<js:ApplicationDataBinding />
</js:beads>
<js:initialView>
<js:View height="100%" width="100%">
<js:beads>
<js:VerticalLayoutWithPaddingAndGap paddingTop="10" paddingBottom="10" paddingRight="20" paddingLeft="20" />
</js:beads>
<js:Container id="startPage" visible="true">
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="20" />
</js:beads>
<js:style>
<js:SimpleCSSStyles padding="20" />
</js:style>
<js:Image src="logos/asf_logo.png" height="175" width="429" />
<js:Label text="How much you you know about Apache policy?" />
<js:Label text="{maxQuestions} questions loaded" />
<js:HContainer>
<js:Label text="No of questions to ask:" />
<js:TextInput id="newQuestions" text="{noQuestions}" change="noQuestions = Number(newQuestions.text)" />
</js:HContainer>
<js:VContainer>
<js:Label text="Level:" />
<js:RadioButton id="easy" groupName="setLevel" width="100%" selected="true" text="Easy" change="{level = 1}" />
<js:RadioButton id="medium" groupName="setLevel" width="100%" text="Medium" change="{level = 2}"/>
<js:RadioButton id="hard" groupName="setLevel" width="100%" text="Hard" change="{level = 3}"/>
</js:VContainer>
<js:TextButton text="Start Quiz" click="begin()" />
</js:Container>
<js:Container id="questionPage" visible="false">
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="20" />
</js:beads>
<js:style>
<js:SimpleCSSStyles padding="20" />
</js:style>
<js:MultilineLabel text="{ask}" width="500" />
<js:Container id="checkboxes" width="500">
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="10" />
</js:beads>
<js:CheckBox id="checkbox1" width="100%" />
<js:CheckBox id="checkbox2" width="100%" />
<js:CheckBox id="checkbox3" width="100%" />
<js:CheckBox id="checkbox4" width="100%" />
<js:CheckBox id="checkbox5" width="100%" />
<js:CheckBox id="checkbox6" width="100%" />
<js:CheckBox id="checkbox7" width="100%" />
<js:CheckBox id="checkbox8" width="100%" />
</js:Container>
<js:MultilineLabel width="100%" text="NOTE that no answer, or one or more than one answer, could be right. Please tick all you think are correct. Each answer must be correct on its own not in combination with other answers." />
<js:MultilineLabel width="100%" text="DISCLAIMER This is still a work in progress and some questions may need improvement and may not be in line with policy." />
<js:TextButton text="Next Question" click="result()" />
</js:Container>
<js:Container id="resultPage" visible="false">
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="20" />
</js:beads>
<js:style>
<js:SimpleCSSStyles padding="20" />
</js:style>
<js:Label text="You got it right" visible="{right}" />
<js:Label text="Sorry that's not quite right. Here is some help so you'll get it right next time." visible="{!right}"/>
<js:Label text="But you were close. These are tricky questions and are trying to trip you up." visible="{!right && noright > 50}"/>
<js:VContainer>
<js:MultilineLabel text="{reason}" width="500" />
</js:VContainer>
<js:Container id="hints" width="500">
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="10" />
</js:beads>
<js:MultilineLabel id="questionAgain" text="" />
<js:Container>
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="5" />
</js:beads>
<js:CheckBox id="answer1" width="100%" />
<js:MultilineLabel id="hint1" width="100%" />
</js:Container>
<js:Container>
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="5" />
</js:beads>
<js:CheckBox id="answer2" width="100%" />
<js:MultilineLabel id="hint2" width="100%" />
</js:Container>
<js:Container>
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="5" />
</js:beads>
<js:CheckBox id="answer3" width="100%" />
<js:MultilineLabel id="hint3" width="100%" />
</js:Container>
<js:Container>
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="5" />
</js:beads>
<js:CheckBox id="answer4" width="100%" />
<js:MultilineLabel id="hint4" width="100%" />
</js:Container>
<js:Container>
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="5" />
</js:beads>
<js:CheckBox id="answer5" width="100%" />
<js:MultilineLabel id="hint5" width="100%" />
</js:Container>
<js:Container>
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="5" />
</js:beads>
<js:CheckBox id="answer6" width="100%" />
<js:MultilineLabel id="hint6" width="100%" />
</js:Container>
<js:Container>
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="5" />
</js:beads>
<js:CheckBox id="answer7" width="100%" />
<js:MultilineLabel id="hint7" width="100%" />
</js:Container>
<js:Container>
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="5" />
</js:beads>
<js:CheckBox id="answer8" width="100%" />
<js:MultilineLabel id="hint8" width="100%" />
</js:Container>
</js:Container>
<js:Container id="links" width="500">
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="10" />
</js:beads>
<js:Label id="seealso" text="See also:" />
<html:A id="link1" width="100%" />
<html:A id="link2" width="100%" />
<html:A id="link3" width="100%" />
<html:A id="link4" width="100%" />
<html:A id="link5" width="100%" />
<html:A id="link6" width="100%" />
<html:A id="link7" width="100%" />
<html:A id="link8" width="100%" />
</js:Container>
<js:TextButton text="Next Question" click="endQuiz()" />
</js:Container>
<js:Container id="scorePage" visible="false">
<js:beads>
<js:VerticalLayoutWithPaddingAndGap gap="20" />
</js:beads>
<js:style>
<js:SimpleCSSStyles padding="20" />
</js:style>
<js:Label text="You scored {score} out of {total}." />
<js:TextButton text="Try Again" click="settings()" />
</js:Container>
<js:Label text="Copyright © 2018 Justin Mclean, Licensed under the Apache License, Version 2.0." />
<js:Label text="Apache, the Apache feather logo are trademarks of The Apache Software Foundation." />
</js:View>
</js:initialView>
</js:Application>