Hi! I’m new to Flash AS3, but can’t find the solution to the problem that i’ve encountered.
I took a template to create a flash game using AS3 and it uses a class that first runs a movieclip where the game is played. So when the game runs, I set a countdown timer to count down from 60 to 0. When it hits 0, I want to go to another movieclip.
Unfortunately, I have no idea how to access the other movieclip.
My code are as follows
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class color_match extends Sprite {
private var ending_sc:endScene = new endScene();
private var first_tile:colors;
private var second_tile:colors;
private var pause_timer:Timer;
private var countdown_timer:Timer;
private var score:Number=0;
var colordeck:Array = new Array(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8);
public function color_match() {
for (x=1; x<=4; x++) {
for (y=1; y<=4; y++) {
var random_card = Math.floor(Math.random()*colordeck.length);
var tile:colors = new colors();
tile.col = colordeck[random_card];
colordeck.splice(random_card,1);
tile.gotoAndStop(9);
tile.x = (x-1)*82;
tile.y = (y-1)*82;
tile.addEventListener(MouseEvent.CLICK,tile_clicked);
addChild(tile);
score_text.visible=true;
score_text.text="Score: "+String(score);
timer_countdown();
}
}
}
public function tile_clicked(event:MouseEvent) {
var clicked:colors = (event.currentTarget as colors);
if (first_tile == null) {
first_tile = clicked;
first_tile.gotoAndStop(clicked.col);
}
else if (second_tile == null && first_tile != clicked) {
second_tile = clicked;
second_tile.gotoAndStop(clicked.col);
if (first_tile.col == second_tile.col) {
pause_timer = new Timer(1000,1);
pause_timer.addEventListener(TimerEvent.TIMER_COMPLETE,remove_tiles);
score++;
score_text.text="Score: "+String(score);
pause_timer.start();
}
else {
pause_timer = new Timer(1000,1);
pause_timer.addEventListener(TimerEvent.TIMER_COMPLETE,reset_tiles);
pause_timer.start();
}
}
}
public function reset_tiles(event:TimerEvent) {
first_tile.gotoAndStop(9);
second_tile.gotoAndStop(9);
first_tile = null;
second_tile = null;
pause_timer.removeEventListener(TimerEvent.TIMER_COMPLETE,reset_tiles);
}
public function remove_tiles(event:TimerEvent) {
removeChild(first_tile);
removeChild(second_tile);
first_tile = null;
second_tile = null;
pause_timer.removeEventListener(TimerEvent.TIMER_COMPLETE,remove_tiles);
}
public function timer_countdown(){
var count:Number = 60;
var myTimer:Timer = new Timer(1000,count);
myTimer.addEventListener(TimerEvent.TIMER, countdown);
myTimer.start();
function countdown(event:TimerEvent):void {
time_txt.text = String((count)-myTimer.currentCount);
if(time_txt.text == "0"){
time_txt.text="Your score is:" +score;
myTimer.stop();
}
}
}
}
}
colors and endScore are the name of the movieclips that are in my .fla file.
Please help! Sorry if this was answered before and thanks!