Actionscript quiz game using adobe animate - actionscript-3

Hi im new to actionscript and I and my classmates are making a quiz game using adobe animate. What i want to happen is when a user tap the checkbutton the checkbutton will check if the the answer that the user inputted in the textbox is correct or wrong. When the Answer matched the correct answer it will go to the next page which is frame3 and when it is wrong it will only stay in its currentframe. the problem is even when the answer that is inputted is correct and it matched with the right answer it wont proceed to the other frame it will always stay in its currentframe, as if like the
if(textbox.text == "correctanswer") is ignored.
I hope you can help me :) Thanks in Advance
checkbutton_2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopFromFrame_2);
function fl_ClickToGoToAndStopFromFrame_2(event:MouseEvent)
{
if(textbox.text == "correctanswer"){
gotoAndStop(3);
}else{
gotoAndStop(2);
}
}

Related

AS3 - How do I code a particular frame?

So its like I want a code just for frame 2. Is there any other way other than just going to frame 2 and typing in the Actions Panel? For example I am using a class called supportForce and I want a part of the code to apply only for frame 2. This might be stupid but just in order to get a doubt cleared I asked this question, forgive me if I am wasting your time. Thanks in advance.
Sure, simply write your code from the parent scope of supportForce inside a statement such as this one:
if(supportForce.currentFrame == 2) { //DO MAGIC ON FRAME 2! }

User interface flash AS 3.0

since the Site seems to be pretty buggy i have to post my question below. Sorry for the inconvenience.
Hi guys
I'm new to flash and i want to create a GUI for my little game.
How can i create a start window where I can select stuff like how many objects to spawn or move speed of my character.
My first idea was to hide everything else on the stage until I click start.
Would that be right. Is the a better way. how to do this anyway.
And where do i put my GUI script. Stage or extern class.
Place your start button in the first frame and put your other elements in second frame. On click of the start button gotoAndPlay to next frame.

Fast rollOver on a button causes another label to rollOut (MovieClip button)

I'm new to AS3/Flash and stackoverflow and have tried to browse through different threads with this issue.
My issue is that when I rollover too quickly on one of my buttons, the button will rollover to the "Click" state. I have a tester that debugs the line "hit! " and whenever that glitch happens, the tester does not show the line "hit" so I know that it isn't actually registering a user-input click.
Interestingly enough, the issue also only happens when I move from the bottom or top of the button to the other side vertically. Faster FPS does seem to minimize the effect but it's still there. I have tried to get rid of my hit area layer, thinking that it was the culprit to the problem somehow but even then it did not do anything.
I'll post the .fla in case anybody can figure this out, would truly appreciate it as it's been driving me nuts.
https://dl.dropboxusercontent.com/u/18672917/Main_Btn_7halp6.fla
Here's the code I used in case someone wants to figure it out solely from possible coding errors. (Also, better_mc.Hit._visible = false; doesn't work it seems)
import flash.events.MouseEvent;
stop();
better_mc.addEventListener(MouseEvent.ROLL_OVER, betterOver);
better_mc.addEventListener(MouseEvent.ROLL_OUT, betterOut);
better_mc.addEventListener(MouseEvent.CLICK, betterClick);
function betterOver(evt:MouseEvent):void{
better_mc.gotoAndPlay("Over");
}
function betterOut(evt:MouseEvent):void{
better_mc.gotoAndPlay(27- (better_mc.currentFrame-10));
}
function betterClick(event:MouseEvent):void {
better_mc.gotoAndPlay("Click");
}
better_mc.hitArea = better_mc.Hit;
better_mc.addEventListener(MouseEvent.MOUSE_DOWN, Hitbox);
function Hitbox (event:MouseEvent){
trace("hit! "+this.name);
better_mc.Hit._visible = false;
};
Ok, got it. this is what is happening
Your calculation on rollout is creating a problem
function betterOut(evt:MouseEvent):void{
**better_mc.gotoAndPlay(27- (better_mc.currentFrame-10));**
}
This expression sometimes returns frame number 28 which is ahead of your 'stop()' which is at frame 27 and so it goes on playing the whole click animation.
27- (better_mc.currentFrame-10)
Try the simple solution of adding 'stop()' before your click animation starts i.e. frame 31 in this case.
See if this sorts your issue.
Can not open your fla as i have CS5 so not much help on that
Not sure why you need both click and mousedown events, code seems fine apart from the gotoAndPlay(labelname) parts since no idea how the animations are added here
Just for the last part of your query
(Also, better_mc.Hit._visible = false; doesn't work it seems)
For AS3, property 'visible' is used and not '_visible' so it will be,
better_mc.Hit.**visible** = false;

leaving and revisting a scene keeping any user input changes the same. Can it be done?

Hi Im relatively new to flash developing and i have a quick question about saving user input. I have a maze scene whereby the user navagates a character around until confronted with another object, when the character hits the object a new scene is opened promting the user to pick a solution to a problem. Once the user clicks the correct answer a box appears saying return to the maze, however when clicked and returned to the maze the character starts back in its original postion, where as I would like the scene to resume where it left off, ie the character is at the point where it collided with the object, the object has dissappeared and the character can resume on the same course.
Thanks for giving this a read I hope it makes sense and some one has a solution for me.
I did have some nice images to explain it better but apprently i need 10 reputation points to upload those.
EDIT: First Id like to say thanks for the rep points you bunch of stars and secondly I know using scenes in flash is seriously cr*p practice and outdated but its the way I learnt all those years ago and seen as Flash itself will be outdated soon Im not really looking to learn another approach using sprites or frames, I just kind of want a fix for this way if poss thank you for answering!
EDIT: Wanting the red rectangle to be removed from the scene once the black square collides with it. It also takes you to the next frame upon doing so. here is my code.
addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
function fl_EnterFrameHandler (event:Event):void
{
if (player.hitTestObject(Risk))
{
removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
removeChild(Risk);
nextFrame();
}
}
I'd suggest you forget about Scenes! They are old, buggy, bring loads of issues with code and are generally a Bad Pratice!! So if you are just learning AS3, dont learn with Scenes!!
Use MovieClips or Sprites instead. And just add and remove them as you need!
EDIT:
To ur edit ;)
and seen as Flash itself will be outdated soon
thats just plain false and a widespread misinformation. It just has a new purpose like MultiPlattform Game Development. But thats a whole different discussion.
You could solve this by saving the x,y coordinates and then restoring them. But i promise you, you will run in to alot more problems/bugs as you go allong!
Like saved Points and Time. Will you triger the Questionscene again when u place the player on the object(last Position). Save the answers, and so on ...
Changing to DisplayObjects will save you time in the end. Just saying ;)
EDIT2:
your code in the comment should look like this:
function fl_EnterFrameHandler (event:Event):void
{
if (player.hitTestObject(Risk))
{
removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);//remove to prevent errors if it fires again and there is no Object to hitTest
removeChild(Risk);// do what needs to be done on this frame
nextFrame();// and then move to the next
}
}
And following correct convetions and make everybody's life easier reading this, it would look like this!
function fl_EnterFrameHandler (event:Event):void
{
if (player.hitTestObject(risk))
{
removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);//remove to prevent errors if it fires again and there is no Onject to hitTest
removeChild (risk);
nextFrame ();
}
}
i'm probaly confusing u now, just use the top one ;)
EDIT3:
Ok, i just had a butchers at it. It's all on a single Frame now. I would have prefered Classes but that'lljust confuse you.
To add new qestions you just have to dublicate the Question MovieClip in the Library and change texts, leave instance names the same tho, then the code will work as is!
DOWLOAD
It is certainly possible. You would store the characters attributes (e.g. current position) within a variable. Then on returning to your game you would use this variable to set the starting position of your character.
I agree that scenes are not the ideal route you should be taking. Possibly reading a good AS3 book would save you hours/days/weeks in the long run.

Button that only works once in flash actionscript 3.0

I have this collecting item game which u have to collect enough "stars" in order to acess a button. After I clicked the "star" button, it suppose to disappear and never appear again. However, when using this script, although the button disappear once I clicked it, when I returned to the frame after going to another frame, it appeared again! pls help!
star1.addEventListener(MouseEvent.CLICK,gotstar);
function gotstar(event:MouseEvent){
stars++;
star1.x = -500;
}
Are you coding on the frames themselves? If so every time you enter a frame it will run every piece of contained code, even if it has already ran once. A solution to this would be to use a document class to track the progress of the game.
you need to remove it from the stage if I understand.
try this instead of star1.x = -500;
stage.removeChild(star1);
star1.removeEventListener(MouseEvent.CLICK,gotstar);
star1.parent.removeChild(star1); in the click handler code (gotstar) should help
however posting your .fla file might be useful for better understanding