Highlighted

Brings back last page

Community Beginner ,
Jan 28, 2019

Copy link to clipboard

Copied

Hello!

I'm currently building an App were I have found all coding necessary in

the code snippets and on the internet. Only one line of code is missing

for me to finish my project and I have absolutely no idea how it should

written. Here it goes:

I have a series of 8 questions with multiple answers. When a question is

answered (right or wrong), the next question appears.This way, the

navigation throughout the 8 questions corresponds to a never ending loop.

On each of those questions is a countdown timer of 45 seconds that leads

back to the Home page. That specific page is not part of the 8 questions

loop navigation.

The code that I wish to include is one that will allow te player to simply

go back to the last question previously unanswered when the timer brought

the player to the Home page. I don't want the home page to always

lead to the same first question at the start of a game.

If these explinations are unclear, plz let me know and I will clarify.

Thanks in advance,

Karol

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

My solution is to have a variable that stores the current frame everytime the time is up.

Just remember to run a check so your variable won't reset.

Here is a sample of how you can set this whole quiz game in one single frame.

AS3 code:

import flash.events.MouseEvent;

import flash.utils.Timer;

import flash.events.TimerEvent;

var time:uint = 45;

var tempTime:uint = time;

var timer:Timer;

if (!this.started)

{

    var lastQuestion:uint = 5;

    this.started = true;

}

function startTimer():void

{

    tempTime = time;

    setText();

    timer = new Timer(1000, time);

    timer.addEventListener(TimerEvent.TIMER, timerHandler);

    timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerCompleteHandler);

    timer.start();

}

function stopTimer():void

{

    timer.removeEventListener(TimerEvent.TIMER, timerHandler);

    timer.removeEventListener(TimerEvent.TIMER_COMPLETE, timerCompleteHandler);

    timer.stop();

}

function timerHandler(e:TimerEvent):void

{

    tempTime--;

    setText();

}

function timerCompleteHandler(e:TimerEvent):void

{

    stopTimer();

    lastQuestion = currentFrame;

    gotoAndStop(1);

}

function setText():void

{

    timerText.text = String(tempTime);

}

function nextQuestion(e:MouseEvent):void

{

    stopTimer();

    gotoAndStop(currentFrame + 5);

  

    if (currentLabel != "end")

        startTimer();

    else

    {

        restartButton.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void

        {

            stopTimer();

            gotoAndStop(1);

        });

    }  

}

function start():void

{

    stop();

    startButton.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void

    {

        gotoAndStop(lastQuestion);

        startTimer();

        trueButton.addEventListener(MouseEvent.CLICK, nextQuestion);

        falseButton.addEventListener(MouseEvent.CLICK, nextQuestion);

    });

}

start();

FLA download:

animate_cc_as3_quiz_game.zip - Google Drive

I hope this helps.

Regards,

JC

TOPICS
ActionScript

Views

221

Likes

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

Brings back last page

Community Beginner ,
Jan 28, 2019

Copy link to clipboard

Copied

Hello!

I'm currently building an App were I have found all coding necessary in

the code snippets and on the internet. Only one line of code is missing

for me to finish my project and I have absolutely no idea how it should

written. Here it goes:

I have a series of 8 questions with multiple answers. When a question is

answered (right or wrong), the next question appears.This way, the

navigation throughout the 8 questions corresponds to a never ending loop.

On each of those questions is a countdown timer of 45 seconds that leads

back to the Home page. That specific page is not part of the 8 questions

loop navigation.

The code that I wish to include is one that will allow te player to simply

go back to the last question previously unanswered when the timer brought

the player to the Home page. I don't want the home page to always

lead to the same first question at the start of a game.

If these explinations are unclear, plz let me know and I will clarify.

Thanks in advance,

Karol

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

My solution is to have a variable that stores the current frame everytime the time is up.

Just remember to run a check so your variable won't reset.

Here is a sample of how you can set this whole quiz game in one single frame.

AS3 code:

import flash.events.MouseEvent;

import flash.utils.Timer;

import flash.events.TimerEvent;

var time:uint = 45;

var tempTime:uint = time;

var timer:Timer;

if (!this.started)

{

    var lastQuestion:uint = 5;

    this.started = true;

}

function startTimer():void

{

    tempTime = time;

    setText();

    timer = new Timer(1000, time);

    timer.addEventListener(TimerEvent.TIMER, timerHandler);

    timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerCompleteHandler);

    timer.start();

}

function stopTimer():void

{

    timer.removeEventListener(TimerEvent.TIMER, timerHandler);

    timer.removeEventListener(TimerEvent.TIMER_COMPLETE, timerCompleteHandler);

    timer.stop();

}

function timerHandler(e:TimerEvent):void

{

    tempTime--;

    setText();

}

function timerCompleteHandler(e:TimerEvent):void

{

    stopTimer();

    lastQuestion = currentFrame;

    gotoAndStop(1);

}

function setText():void

{

    timerText.text = String(tempTime);

}

function nextQuestion(e:MouseEvent):void

{

    stopTimer();

    gotoAndStop(currentFrame + 5);

  

    if (currentLabel != "end")

        startTimer();

    else

    {

        restartButton.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void

        {

            stopTimer();

            gotoAndStop(1);

        });

    }  

}

function start():void

{

    stop();

    startButton.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void

    {

        gotoAndStop(lastQuestion);

        startTimer();

        trueButton.addEventListener(MouseEvent.CLICK, nextQuestion);

        falseButton.addEventListener(MouseEvent.CLICK, nextQuestion);

    });

}

start();

FLA download:

animate_cc_as3_quiz_game.zip - Google Drive

I hope this helps.

Regards,

JC

TOPICS
ActionScript

Views

222

Likes

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
Jan 28, 2019 0
Advisor ,
Jan 28, 2019

Copy link to clipboard

Copied

please paste your code it will be more clear.

Are you using a class or is your code on the first frame?

Likes

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
Reply
Loading...
Jan 28, 2019 0
LEGEND ,
Jan 29, 2019

Copy link to clipboard

Copied

Share the design approach as well.  Does the design spread the questions along the timeline, or it is all program based?  What is used to keep track of which question is currently being presented?  What if the last question previously unanswered was the first but the user just answered the fifth - do you need to keep track of unanswered questions versus answered questions?

Likes

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
Reply
Loading...
Jan 29, 2019 0
Adobe Community Professional ,
Jan 29, 2019

Copy link to clipboard

Copied

Hi.

You can have a variable called something like lastUnansweredQuestion of type uint that everytime the user picks an alternative you set it to the frame of the first question (let's say 2) and everytime the user skips a question you set it to the current question frame.

So everytime the user clicks play you pass the lastUnansweredQuestion as a paramater for the gotoAndStop method.

Please let me know if it makes sense or if you want an example.

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Jan 29, 2019 0
Community Beginner ,
Jan 31, 2019

Copy link to clipboard

Copied

Hello,

So glad you guys are helping out!

First off,

I don't believe that I'm using any class objects. Also, my coding is distributed on different frames within an “action” layer onto my timeline; it’s therefore not all into one page. The first line of code which I use is placed on every frame of my program. The “click go to and stop” as follows:

button_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_5);

function fl_ClickToGoToAndStopAtFrame_5(event:MouseEvent):void

{

    gotoAndStop(10);

}

          My eight questions are placed on their own individual frames and succeed each other with the help of the “click go to and stop” line of code. Just to be clear, here is how it’s built:

Home page = frame 1

Question 1 = frame 5

Question 2 = frame 10

Question 3 = frame 15

Question 4 = frame 20

Question 5 = frame 25

Etc…

The questions always relay in the same order: 1,2,3,4,5,6,7,8,1,2,3,4,6,7,8,1,2,3,4 ... and so on. Question 1 will forever be followed by question 2; question 8 will be followed by question 1.

             Now, the second line of code I use is the countdown timer which I have placed on each of the 8 frames with questions. This allows the Home page to pop up everytime 45 seconds have passed without any action from the player:

var myTimer:Timer = new Timer(1000,35); // every second for 45 seconds

  1. myTimer.addEventListener(TimerEvent.TIMER, onTimer);
  2. myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onComplete);
  3. myTimer.start();

function onTimer(e: TimerEvent):void {

timer_txt.text = String(myTimer.repeatCount - myTimer.currentCount);

}

function onComplete(e: TimerEvent):void{

gotoAndStop(1);

}

             Lastly, “Home page” has a start button. My goal is to place a line of code on that “start button” which allows the program to track the last frame on which it was standing before the Home page came up. In this scenario, “last frame” corresponds to the last unanswered question. For example, a player answers the first 4 question (right or wrong) and arrives onto the fifth (frame 25), gets bored and leaves. Half an hour goes by where the game was left untouched, the same player comes back and presses the “Home page” start button where he immediately ends up onto question 5 (frame 25). Wherever a player might leave the game (whichever frame), the start button has to lead back to the previous unanswered question.

Hope this helps to clarify my work,

Thanks again

Likes

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
Reply
Loading...
Jan 31, 2019 0
Advocate ,
Jan 31, 2019

Copy link to clipboard

Copied

Hi parcscanada

If everything happens on one timeline

set in "action" layer script in frame 1 (your Home page a variable

var lastOpenQuestion: uint = 5; //this is at first your default first question

and in each question frame set the value of this variable to the particular frame number to have it stored when onComplete strikes

function onComplete(e: TimerEvent): void {

    lastOpenQuestion = currentFrame;

    gotoAndStop(1);

}

On frame 1 (Home page) again below the setting of the new variable

startButton.addEventListener(MouseEvent.CLICK, startButtonHandler);

function startButtonHandler(e:MouseEvent) {

    gotoAndStop(lastOpenQuestion);

}

This assumes that your start button is instance-named "startButton".

I think that should do the trick

Klaus

Likes

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
Reply
Loading...
Jan 31, 2019 0
Adobe Community Professional ,
Jan 31, 2019

Copy link to clipboard

Copied

Hi, Klaus.

Your idea is similar to mine.

Just remember that if you don't run a check in your lastOpenQuestion variable, it will reset to the declaration value everytime the player goes back to the home page.

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Jan 31, 2019 0
Advocate ,
Feb 01, 2019

Copy link to clipboard

Copied

Hi João

You are right. I didn't think it through enough.

Klaus

Likes

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
Reply
Loading...
Feb 01, 2019 1
Adobe Community Professional ,
Jan 31, 2019

Copy link to clipboard

Copied

My solution is to have a variable that stores the current frame everytime the time is up.

Just remember to run a check so your variable won't reset.

Here is a sample of how you can set this whole quiz game in one single frame.

AS3 code:

import flash.events.MouseEvent;

import flash.utils.Timer;

import flash.events.TimerEvent;

var time:uint = 45;

var tempTime:uint = time;

var timer:Timer;

if (!this.started)

{

    var lastQuestion:uint = 5;

    this.started = true;

}

function startTimer():void

{

    tempTime = time;

    setText();

    timer = new Timer(1000, time);

    timer.addEventListener(TimerEvent.TIMER, timerHandler);

    timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerCompleteHandler);

    timer.start();

}

function stopTimer():void

{

    timer.removeEventListener(TimerEvent.TIMER, timerHandler);

    timer.removeEventListener(TimerEvent.TIMER_COMPLETE, timerCompleteHandler);

    timer.stop();

}

function timerHandler(e:TimerEvent):void

{

    tempTime--;

    setText();

}

function timerCompleteHandler(e:TimerEvent):void

{

    stopTimer();

    lastQuestion = currentFrame;

    gotoAndStop(1);

}

function setText():void

{

    timerText.text = String(tempTime);

}

function nextQuestion(e:MouseEvent):void

{

    stopTimer();

    gotoAndStop(currentFrame + 5);

  

    if (currentLabel != "end")

        startTimer();

    else

    {

        restartButton.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void

        {

            stopTimer();

            gotoAndStop(1);

        });

    }  

}

function start():void

{

    stop();

    startButton.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void

    {

        gotoAndStop(lastQuestion);

        startTimer();

        trueButton.addEventListener(MouseEvent.CLICK, nextQuestion);

        falseButton.addEventListener(MouseEvent.CLICK, nextQuestion);

    });

}

start();

FLA download:

animate_cc_as3_quiz_game.zip - Google Drive

I hope this helps.

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Jan 31, 2019 1
Community Beginner ,
Feb 01, 2019

Copy link to clipboard

Copied

Wow!!

Your code JoãoCésar is much more efficient than what I had before.

I'm so impressed by the help you all have given me.

I cannot thank you enough you guys!!

Karol

Likes

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
Reply
Loading...
Feb 01, 2019 1
Adobe Community Professional ,
Feb 01, 2019

Copy link to clipboard

Copied

This is excellent, Karol!

You're welcome!

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Feb 01, 2019 0