Copy link to clipboard
Copied
Hello to all. I'm new to flash. I'm using adobe flash cs 5.5 (action script 3.0). I created a quiz game (multiple choice, true/false) and I'd like to put a result page, a timer ( 2minutes ), and a dialog box ( I don't know what you call it in flash) that will appear displaying the message "correct" or "incorrect" when the user clicks on the answer and then proceeds on the next question. I'm eager to learn these things. Thanks in advance!
to display a result page (presumably displaying the number of correct responses and/or number of incorrect responses etc), you will need to use, at least, one variable to track the total correct responses:
var correctNum:int=0; // and possibly you'll want to initialize an incorrectNum variable.
// and each time an question is answered correctly, update correctNum:
correctNum++;
// on your result page, you'll have at least one dynamic textfield (eg, correctNum_tf) to display correctNum:
correctNum_tf
...Copy link to clipboard
Copied
to display a result page (presumably displaying the number of correct responses and/or number of incorrect responses etc), you will need to use, at least, one variable to track the total correct responses:
var correctNum:int=0; // and possibly you'll want to initialize an incorrectNum variable.
// and each time an question is answered correctly, update correctNum:
correctNum++;
// on your result page, you'll have at least one dynamic textfield (eg, correctNum_tf) to display correctNum:
correctNum_tf.text="The number of correct responses: "+correctNum;
// to display a correct/incorrect message after each question is answered (or timed-out), create a movieclip to display after each question is answered. at least add a dynamic textfield to it (eg, tf) and a close button (eg, close_btn) and assign the movieclip a class (eg, Feedback). you can then call feedbackF and pass the string you want to display in your feedback movieclip:
function feedbackF(s:String):void{
var fb:Feedback=new Feedback();
addChild(fb);
fb.tf.text=s;
fb.close_btn.addEventListener(MouseEvent.CLICK,closeF);
}
function closeF(e:MouseEvent):void{
e.currentTarget.removeEventListener(MouseEvent.CLICK,closeF);
removeChild(e.currentTarget.parent);
}
// for each question, you might have a correct string (eg, correctS) to display in your feedback movieclip and an incorrect string(eg, incorrectS) if you want the feedback for each question to be tailored to that question. ie, you are giving more info than a simple correct/incorrect.
// for your timer, use the Timer class:
// this initialization only needs to be done once:
var t:Timer=new Timer(120000,1); //120000 ms = 2 minutes
t.addEventListener(TimerEvent.TIMER,timeoutF);
function timeoutF(e:TimerEvent):void{
// this current question timed-out. update incorrectNum (if you have such a variable) and call feedbackF:
feedbackF("Your time to answer this question expired\n\n"+incorrectS);
}
// at the start of each question use:
t.reset();
t.start();
Copy link to clipboard
Copied
hi kglad! thanks for the quick reply. About displaying the "correct/incorrect" dialogbox, is it simplier to place a tweened picture (zooming correct picture),fades out and then moves to the next question? And about the timer, I don't get it. Am I suppose to place the code to the textbox to display the timer? Thanks again kglad.
Copy link to clipboard
Copied
for your correct/incorrect dialogbox, it's simpler to use a movieclip like i showed. it may seem intimidating but it's simpler because you don't need to create a new animation for each question.
if you only have one question, you can hardcode the correct and incorrect animation and that would be workable. but if you have 10 questions or 100 questions, doing it the way i showed is much simpler and much quicker and will look consistant and professional.
if you want to display the timer to your user, you will need to use a textfield, for example, timer_tf. you could then use:
// this initialization only needs to be done once:
var t:Timer=new Timer(1000,120); //1000 ms = 1 second
t.addEventListener(TimerEvent.TIMER,timerF);
function timertF(e:TimerEvent):void{
timer_tf.text = "Time Remaining = "+formatF(120-t.currentCount)+" seconds";
if(t.currentCount==120){
// this current question timed-out. update incorrectNum (if you have such a variable) and call feedbackF:
feedbackF("Your time to answer this question expired\n\n"+incorrectS);
}
}
function formatF(n:int):String{
var min:int=Math.floor(n/60);
var sec:int = n-min*60;
minS=padF(min);
secS=padF(sec);
return min+":"+sec;
}
function padF(n:int):String{
var s:String=n.toString();
while(s.length<2){
s="0"+s;
}
return s;
}
// at the start of each question use:
t.reset();
t.start();
// when a question is answered, use:
t.stop(); // to stop the timer.
Copy link to clipboard
Copied
Sorry for the late reply. I'm done with the dialogboxes and timer. Thanks for your help! Your a life saver. How about adding sounds for every button I press? and adding background music at layer 1? And is it possible to open an exe or swf file within my flash file?
Copy link to clipboard
Copied
use the sound class to play and control sounds: in your library assign a class to those two sounds (eg, BG_sound and Press_sound) and you can use:
var bg_sound:BG_sound=new BG_sound();
bg_sound.play();
var press_sound:Press_sound=new Press_sound();
your_button.addEventListener(MouseEvent.MOUSE_DOWN,downF);
function downF(e:MouseEvent):void{
press_sound.play();
}
// you can load a swf file using the loader class:
var loader:Loader=new Loader();
addChild(loader);
loader.load(new URLRequest("yourswf.swf"));
Copy link to clipboard
Copied
yea! I have my background music now. I'll try to add some on my buttons later. Is it the same procedure? And about loading an swf file, I have 4 buttons on my homepage (HOME, LESSONS, QUIZ, CREDITS). I want to open a separate swf file when I click QUIZ button. And will it play continuosly when I click the BACK button(returns to homepage)? sorry for asking silly questions. I'm new in coding Can an AS3 load an AS2 coded swf?
Copy link to clipboard
Copied
I tried to load swf(as2) in my swf(as3) and this error showed up:
ArgumentError: Error #2180: It is illegal to move AVM1 content (AS1 or AS2) to a different part of the displayList when it has been loaded into AVM2 (AS3) content.
at flash.display::DisplayObjectContainer/addChild()
at fl.display::ProLoader/loadDoneCallback()
at fl.display::ProLoaderInfo/handleLoaderInfoEvent()
Copy link to clipboard
Copied
yes, and as3 file can load an as2 file.
click file>publish settings>swf and tick "permit debugging". restest. the problematic line number will be in the error message. copy and paste that line of code.
Copy link to clipboard
Copied
Scene=Scene 1, layer=Actions, frame=62, Line 10 | The class or interface 'MouseEvent' could not be loaded. |
I got 102 errors and tweening effect is gone. I can't click a button. All error says "The class or interface 'MouseEvent' could not be loaded." at different frames.
This is my publish setting:
Flash Player: 10.2
Script: action script 2.0
and I ticked permit debugging.
Copy link to clipboard
Copied
you can't use as3 code in an as2 swf.
Copy link to clipboard
Copied
is there a way to open an as2 swf? convert it to an exe file?
Copy link to clipboard
Copied
you can load an as2 swf into an as3 swf using the code i showed in message 5.
Copy link to clipboard
Copied
I tried to search on the net on how to react with button clicks. And it worked fine. With the use of mouse event I'm almost finished thanks for all the help. Is there a way i can open an html document?
Copy link to clipboard
Copied
you can use navigateToURL(new URLRequest("yourhtml.html")) to open an html document in your browser.
Copy link to clipboard
Copied
hi kglad! I'm done with my swf. Thank you! But there's a problem in showing my swf in browser. Other pictures can't be seen. How do you put a scroll bar? I'm playing the swf in a browser. Many thanks!
Copy link to clipboard
Copied
at the top of your embedding html page you'll see:
<style type="text/css" media="screen"> | ||
html, body { height:100%; background-color: #ffffff;} | ||
body { margin:0; padding:0; overflow:hidden; } | ||
#flashContent { width:100%; height:100%; } | ||
</style> |
change that to:
<style type="text/css" media="screen"> | ||
html, body { height:100%; background-color: #ffffff;} | ||
body { margin:0; padding:0; } | ||
#flashContent { width:100%; height:100%; } | ||
</style> |
Copy link to clipboard
Copied
yes! thanks a lot! one last question, how can I load an html document with a button click in my flash file(as3) without using internet? My html document is stored in my computer.
Copy link to clipboard
Copied
if this is an air application you can use the htmlloader class to load and display that html file. is your quiz and air app?
Copy link to clipboard
Copied
Not an air app. Just an ordinary swf as3 file. I used navigateToURL as you mentioned at #14 and changed the path. I just finished my presentation. Thank you kglad. (and thanks to Ned for giving me ideas about the paths).
Copy link to clipboard
Copied
for a web-based swf, using navigateToURL is your only option. the html file can be opened in a new browser window/tab, the same window/tab or in the frame of an html page with an iframe setup.