Copy link to clipboard
Copied
In my boredom I am trying to create the contestant podiums from Sale of The Century and have them set up to look like the TV show (see here: https://youtu.be/rZSdhRZQjak?t=25s). Now this is done between 5 frames on the timeline (with a different graphic for each frame. Everything is fine and swell until I added a timer for the speed round. I created a dynamic TextField in Flash. The problem is that every time I reset the podium by using the gotoAndStop method, my timer stops as well. I tried moving the textfield (because I have to have a removeChild method as it was created in flash) and the gotoAndStop but that still causes issues. I tried by creating the textfield in AS, but I just got the empty rectangle. Below is the code from the frame that is the default podium position and where the timer is created.
The question is how do I get the timer to continue to run after I had gone through the player "buzzin" frames and back to the default?
stop();
removeChild(srclock_txt);
pScore1.text = (firstPlayerScore).toString();
pScore2.text = (secondPlayerScore).toString();
pScore3.text = (thirdPlayerScore).toString();
pName1.text = firstPlayer;
pName2.text = secondPlayer;
pName3.text = thirdPlayer;
var leftArrow: Boolean = false;
var rightArrow: Boolean = false;
var upArrow: Boolean = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, buzzin);
function buzzin(event: KeyboardEvent): void {
trace(event.keyCode);
if (event.keyCode == 37) {
leftArrow = true;
gotoAndPlay(4);
} else if (event.keyCode == 39) {
rightArrow = true;
gotoAndPlay(14);
} else if (event.keyCode == 38) {
upArrow = true;
gotoAndPlay(9);
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, give_me_60);
function give_me_60(event: KeyboardEvent): void {
var clock_back: Shape = new Shape();
clock_back.graphics.beginFill(0x000000);
clock_back.graphics.lineStyle(3, 0xff0000);
clock_back.graphics.drawRect(262.5, 312.4, 52, 40.6);
clock_back.graphics.endFill();
if (event.keyCode == 84) {
addChild(clock_back);
addChild(srclock_txt);
}}
var countDownDec:Number =1;
var totalSecs = 10;
var countDownSecs = totalSecs;
srclock_txt.text = countDownSecs;
var myTimer:Timer = new Timer (countDownDec*1000);
myTimer.addEventListener(TimerEvent.TIMER, tick);
function tick (e:TimerEvent): void {
if (countDownSecs == 0) {
myTimer.stop ();
} else {
countDownSecs = countDownSecs - countDownDec;
srclock_txt.text = countDownSecs;
}}
stage.addEventListener(KeyboardEvent.KEY_DOWN, start_clock);
function start_clock (event:KeyboardEvent): void {
if (event.keyCode == 71) {
srclock_txt.text = totalSecs;
myTimer.start();
}}
stage.addEventListener(KeyboardEvent.KEY_DOWN, stop_clock);
function stop_clock (event:KeyboardEvent): void {
if (event.keyCode == 83) {
myTimer.stop();
}
}
Copy link to clipboard
Copied
the code you showed in attached to some frame, correct?
and is the problem you are seeing caused by the code you showed re-executing when that frame is re-entered?
Copy link to clipboard
Copied
So the game starts on frame 3. The code is from frame 3 of the Actions layer (1 & 2 is where names are entered and screen initializes the game).
For example, player 1's podium lights up on frames 4-8. When the clock is not there, it is fine. When it is, I get through the frames perfectly. But when I go back to frame 3, the clock & textfield stop (i.e., it freezes on 8).
Thinking my problems was dealing with the code, I moved the the textfield (and thus the removeChild) to frame 2. When I tested that I got the re-executing and thus the clock freezes and starts a new timer in the textfield on top of the previous one.
Does that clear it up?
SIDENOTE: After posting this, I am at the moment trying to see if making the podium frames a MovieClip would solve this, but I am having difficulties with not being able to clear them when I press my reset key. Thus I'm yet to see if this would actually solve my problem. I have a bunch of AS3 books....guess I should have gotten one for Flash *sigh*
Copy link to clipboard
Copied
when your return to the frame that contains that code (frame 3), the code re-executes and it doesn't appear that you want that.
to remedy, you can enclose that code so it only executes the first time the frame is entered and not thereafter:
var alreadyExecuted:Boolean;
if(!alreadyExecuted){
alreadyExecuted=true;
// the code you don't want re-executed...
.
.
.
}
Copy link to clipboard
Copied
I know exactly what you mean; but it didn't seem to work unfortunately. I've tried wrapping it around pretty much every part of the code that deals with the clock and it doesn't seem to work. Bummer. This is the final part needed to complete this sucker. I'm almost willing to send it to you to look at since it's only 100K.
Maybe I'll give it another go in the morning.
Copy link to clipboard
Copied
sounds good.
Copy link to clipboard
Copied
I just spent another couple hours on it to no avail. I am stumped.
Copy link to clipboard
Copied
use the trace function to debug.
Copy link to clipboard
Copied
I did. That's how I felt the issue was with the textbox and tried to create a textbox.
So after I posted my previous reply I putzed around with the copy of the file that I mentioned creating the textfield in AS (that I thankfully saved just in case), and it looks like that I may have solved my own problem by fixing some parameters and embedding the font using script.
Thanks for your help and patience! You have been a big help.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now