Sunday 30 October 2016

SYMBOL PROPERTIES CLASS AS3

SYMBOL PROPERTIES CLASS AS3
SYMBOL PROPERTIES CLASS AS3
SYMBOL PROPERTIES CLASS AS3
ADD CHILD INTO CLASS

------------------------------------------------------------------------------------------------------------
SYMBOL PROPERTIES CLASS AS3  CODE:
0) TYPE MAIN CLASS NAME color_match
1) MAKE MOVIE CLIP SYMBOL 
2) INSIDE MOVIE CLIP MAKE 9 FRAMES WITH DIFFERENT COLORS
3) TYPE NAME  colors IN CLASS BOX
4) SAVE THIS CLASS FILE IN FLA FILE FOLDER WITH NAME
color_match.as
5) HERE SYMBOL PROPERTIES CLASS NAME DIFFERENT WITH
FILE CLASS NAME  OR CODE CLASS NAME
public class color_match extends Sprite {
public function color_match() {
5) WHEN WE START  GAME MOVIE GO TO STOP  ON 9  GRAY FRAME
tile.gotoAndStop(9);

NOTE THAT:
HERE MAIN CLASS NAME AND SYMBOL PROPERTIES CLASS NAME 
DIFFERENT
HERE MAIN FILE CLASS NAME =  color_match
BUT
HERE MOVIE SYMBOL PROPERTIES CLASS NAME NAMEcolors
--------------------------------------------------------------------------------------------------------

READ MORE:
http://www.emanueleferonato.com/2008/05/02/creation-of-a-matching-game-with-flash-and-as3/


This tutorial was inspired by the one written at chapter 3 in ActionScript 3.0 Game Programming University, but I changed some mechanics because I did not like some choices made by the author.
Anyway, this is not a “mine is better”, just a tutorial that I did not write completely on my own.
Do you know what is a matching game?
In this version, you have 16 grey tiles. You can flip two tiles at a time by clicking on them. If colors of the flipped tiles match, they will be removed from the table. If colors don’t match, they turn grey again.
Having 16 matchable tiles means having 8 different colors, and a “void” color to represent the unclicked tile.
The only object used in this movie is this movieclip:
------------------------------------------------------------------------------------------------------------
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 first_tile:colors;
private var second_tile:colors;
private var pause_timer:Timer;
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);
}
}
}
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);
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);
}
}
}

--------------------------------------------------------------------------------------------------------------
HOW SYMBOL PROPERTIES CLASS WORKS IN THIS GAME?
IT TELLS HOW TO WRITE ADD CHILD CODE IN CLASS FORM
HERE MAIN CLASS NAME AND SYMBOL PROPERTIES CLASS NAME 
DIFFERENT
HERE MAIN FILE CLASS NAME =  color_match
BUT
HERE MOVIE SYMBOL PROPERTIES CLASS NAME NAME = colors

--------------------------------------------------------------------------------------------------------------
package{

import flash.display.Sprite;
import flash.events.MouseEvent;

//HERE color_match IS MAIN CLASS NAME

public class color_match extends Sprite {

public function color_match() {
var tile:colors = new colors();
addChild(tile);
tile.addEventListener(MouseEvent.CLICK,tile_clicked);
}

public function tile_clicked(event:MouseEvent) {
trace("tile")
}

}
}

--------------------------------------------------------------------------------------------------------------
OR USE THIS CODE
REMOVE PUBLIC WORD AND CHANGE POSITION THIS LINE
public function tile_clicked(event:MouseEvent) {
trace("tile")
}
--------------------------------------------------------------------------------------------------------------
package{
import flash.display.*;
import flash.events.*;
//HERE color_match IS MAIN CLASS NAME
public class color_match extends Sprite {

public function color_match() {

var tile:colors = new colors();
addChild(tile);
tile.addEventListener(MouseEvent.CLICK,tile_clicked);
function tile_clicked(event:MouseEvent){
trace("tile")
}

}
}
}











EmoticonEmoticon