--------------------------------------------------------------------------------------------------------------------
DOWNLOAD MEMORY GAMES
FIND THIS RED LINE IN GOOGLE
event.currentTarget.removeEventListener(MouseEvent.CLICK, checkCards);
Memory game random function IN FLASH
---------------------------------------------------------------------------------------------------------------------
FIRST YOU NEED TO UNDERSTAND HOW ADD CHILD WORKS IN AS3
READ THIS:
STEP NO:1
1) First Make Movie Clip Symbol And Go To Symbol Properties And CHECKED TWO BOXES
LIKE Export For ActionScript, Export In Frame1 AND GO TO STEP 2 FOR CLASS NAME
STEP NO:2
2) MovieClip Symbol Properties = CircleShape
http://www.republicofcode.com/tutorials/flash/as3displaylist/
var myCircle:CircleShape = new CircleShape();addChild(myCircle);
------------------------------------------------------------------------------------------------------------------
AS3 - CONVERTING THE LOADER INTO MOVIECLIP
FIND THIS RED LINE : loader_mc.addChild(mc); IN GOOGLE
http://www.dynamicdrive.com/forums/archive/index.php/t-33464.html
http://stackoverflow.com/questions/3979751/as3-converting-the-loader-into-movieclip
var myMovieClip:MovieClip = new MovieClip();
myMovieClip.addChild(myLoader);
--------------------------------------------------------------------------------------------------------------------IN THIS TUTORIAL I USE THIS SIMPLE MEMORY GAME
I USE NOTEPAD ++ FOR CHANGE CODE
Memory game random function IN FLASH
1) UNDERSTAND ADD CHILD FUNCTION
2) UNDERSTAND FOR LOOP SYSTEM
2) IMAGE LOADER FUNCTION
BASICALLY IN THIS CODE CARD MOVIE CLIP LOAD SIX MOVIE CLIPS
THIS CODE USE TWO CLASS FILES ITS MAIN CLASS FILE NAME : MemoryGame
SECOND CLASS FILE NAME : Card
Actually MemoryGame IMPOT CLASSES WITH THESE LINES
import Card; (YOUR OUT SIDE CLASS FILES)
import Computer; (YOUR INSIDE MOVIE CLASS FILES)
import BlackMouse; (YOUR INSIDE MOVIE CLASS FILES)
import Radio; (YOUR INSIDE MOVIE CLASS FILES)
import Mobile; (YOUR INSIDE MOVIE CLASS FILES)
import Projector; (YOUR INSIDE MOVIE CLASS FILES)
3) I USE 2 MOVIE CLIPS CODE INSTEAD 6 MOVIE CLIPS AND CHANGE MOVE CLIPS NAME
CAHANGE PRIVATE VARIABLE INTO VARIABLE MemoryGame CLASS FILE
EXAMPLE
private var MyCard:Card; AND RIGHT THIS LINE IN THIS WAY
var MyCard:Card = new Card();
addChild(MyCard);
4) DURING EXPERIMENT I FOUND SOME ERROR LIKE DUPLICATE VARIABLES
SO YOU NEED CHANGE FUNCTION NAME IF GIVE ERROR
5) HOW CHANGE PRIVATE FUNCTION INTO SIMPLE FUNCTION LINE
private function createCards():void{
JUST DELETE BLUE WORD private AND WRITE IN THIS WAY
function createCards():void{
NOW REED REAL CODE:MemoryGame.as
----------------------------------------------------------------------------------------------------------------------
package{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import Card;
import Computer;
import BlackMouse;
import Radio;
import Mobile;
import Projector;
public class MemoryGame extends MovieClip{
private var MyCard:Card;
private var MyComputer:Computer;
private var MyMouse:BlackMouse;
private var MyRadio:Radio;
private var MyMobile:Mobile;
private var MyProjector:Projector;
private var MyCardX:Number;
private var MyCardY:Number;
private var _firstCard:*;
private var _totalMatches:Number;
private var _currentMatches:Number;
public function MemoryGame(){
_totalMatches = 5;
_currentMatches = 0;
createCards();
}
private function createCards():void{
MyCardX = 45;
MyCardY = 31;
for(var A:Number = 0; A < 2; A++){
MyCard = new Card();
addChild(MyCard);
MyComputer = new Computer();
MyCard.setType(MyComputer);
MyCard.x = MyCardX;
MyCard.y = MyCardY;
MyCardX += MyCard.width + 50;
MyCard.addEventListener(MouseEvent.CLICK, checkCards);
}
for(var B:Number = 0; B < 2; B++){
MyCard = new Card();
addChild(MyCard);
MyMouse = new BlackMouse();
MyCard.setType(MyMouse);
MyCard.x = MyCardX;
MyCard.y = MyCardY;
MyCardX += MyCard.width + 50;
MyCard.addEventListener(MouseEvent.CLICK, checkCards);
}
MyCardX = 45;
MyCardY += MyCard.height + 50;
for(var C:Number = 0; C < 2; C++){
MyCard = new Card();
addChild(MyCard);
MyRadio = new Radio();
MyCard.setType(MyRadio);
MyCard.x = MyCardX;
MyCard.y = MyCardY;
MyCardX += MyCard.width + 50;
MyCard.addEventListener(MouseEvent.CLICK, checkCards);
}
for(var D:Number = 0; D < 2; D++){
MyCard = new Card();
addChild(MyCard);
MyMobile = new Mobile();
MyCard.setType(MyMobile);
MyCard.x = MyCardX;
MyCard.y = MyCardY;
MyCardX += MyCard.width + 50;
MyCard.addEventListener(MouseEvent.CLICK, checkCards);
}
MyCardX = 45;
MyCardY += MyCard.height + 50;
for(var E:Number = 0; E < 2; E++){
MyCard = new Card();
addChild(MyCard);
MyProjector = new Projector();
MyCard.setType(MyProjector);
MyCard.x = MyCardX;
MyCard.y = MyCardY;
MyCardX += MyCard.width + 50;
MyCard.addEventListener(MouseEvent.CLICK, checkCards);
}
}
private function checkCards(event:MouseEvent):void{
event.currentTarget.removeEventListener(MouseEvent.CLICK, checkCards);
if(_firstCard == undefined){
_firstCard = event.currentTarget;
}
else if(String(_firstCard._type) == String(event.currentTarget._type)){
_firstCard = undefined;
_currentMatches ++;
if(_currentMatches >= _totalMatches){
}
}
else{
_firstCard.gotoAndPlay("flipBack");
event.currentTarget.gotoAndPlay("flipBack");
_firstCard.addEventListener(MouseEvent.CLICK, checkCards);
event.currentTarget.addEventListener(MouseEvent.CLICK, checkCards);
_firstCard = undefined;
}
}
}
}
-------------------------------------------------------------------------------------------------------------------
NOW REED REAL CODE:Card.as
------------------------------------------------------------------------------------------------------------------
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Card extends MovieClip
{
public var _type:*;
public function Card()
{
this.buttonMode = true;
this.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(event:MouseEvent):void
{
if(this.currentFrame == 1)
{
this.play();
}
}
public function setType(type:*):void
{
_type = type;
loader_mc.addChild(_type);
}
}
}
-------------------------------------------------------------------------------------------------------------------
NOW REED CHANGE CODE: MemoryGame.as
I INCLUDE TWO FILE INT THIS FILES
MemoryGame.as + Card.as
------------------------------------------------------------------------------------------------------------------
package{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import Computer;
import BlackMouse;
public class MemoryGame extends MovieClip{
var FirstCard:*;
var TotalMatches:Number;
var CurrentMatches:Number;
function MemoryGame(){
TotalMatches = 5;
CurrentMatches = 0;
createCards();
}
function createCards():void{
var MyCardX = 45;
var MyCardY = 31;
for(var A:Number = 0; A < 2; A++){
var MyCard:Card = new Card();
addChild(MyCard);
var MyComputer:Computer = new Computer();
MyCard.setType(MyComputer);
MyCard.x = MyCardX;
MyCard.y = MyCardY;
MyCardX += MyCard.width + 50;
MyCard.addEventListener(MouseEvent.CLICK, checkCards);
}
for(var B:Number = 0; B < 2; B++){
var MyCard2:Card = new Card();
addChild(MyCard2);
var MyMouse:BlackMouse = new BlackMouse();
MyCard2.setType(MyMouse);
MyCard2.x = MyCardX;
MyCard2.y = MyCardY;
MyCardX += MyCard2.width + 50;
MyCard2.addEventListener(MouseEvent.CLICK, checkCards);
}
}
function checkCards(event:MouseEvent):void{
event.currentTarget.removeEventListener(MouseEvent.CLICK, checkCards);
if(FirstCard == undefined){
FirstCard = event.currentTarget;
}
else if(String(FirstCard._type) == String(event.currentTarget._type)){
FirstCard = undefined;
CurrentMatches ++;
if(CurrentMatches >= TotalMatches){
}
}
else{
FirstCard.gotoAndPlay("flipBack");
event.currentTarget.gotoAndPlay("flipBack");
FirstCard.addEventListener(MouseEvent.CLICK, checkCards);
event.currentTarget.addEventListener(MouseEvent.CLICK, checkCards);
FirstCard = undefined;
}
}
var _type:*;
function Cardp(){
this.buttonMode = true;
this.addEventListener(MouseEvent.CLICK, onClick);
}
function onClick(event:MouseEvent):void{
if(this.currentFrame == 1){
this.play();
}
}
function setType(type:*):void{
var loader_mc:MovieClip = new MovieClip();
loader_mc.addChild(_type);
_type = type;
loader_mc.addChild(_type);
}
}
}
--------------------------------------------------------------------------------------------------------------------
IN THIS GAME Card MOVIE CLIP loarder_mc MOVIE CLIP
WHICH LOAD MOVIE CLIPS
YOU CAN REMOVE TWEEN BY THIS METHOD
INSIDE CARD MOVIE CLIP loarder_mc WHICH MAKE FLIP ANIMATION
NOW YOU CAN DELETE FLIP ANIMATION
SEE THE PICTURE DELETE TWEEN AND KEEP loader_mc ON FRAME NO 2 TO 40
WIH SAME SIZE
https://www.youtube.com/watch?v=4OqRwYqBwIU
--------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
http://alanct.blogspot.co.uk/2009/03/planing-simple-marvin-and-dexter-card.html
---------------------------------------------------------------------------------------------------------------------
planing a simple marvin and dexter card matching game
I have built a simple card matching game in action script 3.0 using the following code
A actionscript 3.0 file containing the following:
package
{
import flash.display.MovieClip;
import Card;
import Dexter;
import Marv
import flash.events.MouseEvent;
public class MemoryGame extends MovieClip
{
private var _card:Card;
private var _marv:Marv;
private var _dexter:Dexter;
private var _cardX:Number;
private var _cardY:Number;
private var _firstCard:*;
private var _totalMatches:Number;
private var _currentMatches:Number;
public function MemoryGame()
{
_totalMatches = 2;
_currentMatches = 0;
createCards();
}
private function createCards():void
{
_cardX = 45;
_cardY = 31;
for(var i:Number = 0; i < 2; i++)
{
_card = new Card();
addChild(_card);
_marv = new Marv();
_card.setType(_marv);
_card.x = _cardX;
_card.y = _cardY;
_cardX += _card.width + 50;
_card.addEventListener(MouseEvent.CLICK, checkCards);
}
for(var j:Number = 0; j < 2; j++)
{
_card = new Card();
addChild(_card);
_dexter = new Dexter();
_card.setType(_dexter);
_card.x = _cardX;
_card.y = _cardY;
_cardX += _card.width + 50;
_card.addEventListener(MouseEvent.CLICK, checkCards);
}
}
private function checkCards(event:MouseEvent):void
{
event.currentTarget.removeEventListener(MouseEvent.CLICK, checkCards);
if(_firstCard == undefined)
{
_firstCard = event.currentTarget;
}
else if(String(_firstCard._type) == String(event.currentTarget._type))
{
trace("match!");
_firstCard = undefined;
_currentMatches ++;
if(_currentMatches >= _totalMatches)
{
trace("YOU WIN!!!!!!");
}
}
else
{
trace("wrong!");
_firstCard.gotoAndPlay("flipBack");
event.currentTarget.gotoAndPlay("flipBack");
_firstCard.addEventListener(MouseEvent.CLICK, checkCards);
event.currentTarget.addEventListener(MouseEvent.CLICK, checkCards);
_firstCard = undefined;
}
}
}
}
and then another actionscript file containing the information for a card
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Card extends MovieClip
{
public var _type:*;
public function Card()
{
this.buttonMode = true;
this.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(event:MouseEvent):void
{
if(this.currentFrame == 1)
{
this.play();
}
}
public function setType(type:*):void
{
_type = type;
loader_mc.addChild(_type);
}
}
}
the above cord is for loading the different cards movie clip images and puts them on the cards its the traces for if you have a match and once you have 2 matches its say that you have won, I'm going to look in to if you win a certain animation plays and once you have matched them all it has a special animation for the win of the hole game. the two file work together and load on to the main stage, using public and private functions to make the cards on the stage and in places with x and y co-ordinates and setting the size, along with if statement for determining on matches and wins along with variables to add on to the total count of wins, bellow are two screen dumps of the end result as you can see you start with four cards and once all all matched it outputs in the outputs window, i want to take the output and link in to an character animation. this is only a plan. i will be looking at this idea along side two others that i have storyboards for latter on.
A actionscript 3.0 file containing the following:
package
{
import flash.display.MovieClip;
import Card;
import Dexter;
import Marv
import flash.events.MouseEvent;
public class MemoryGame extends MovieClip
{
private var _card:Card;
private var _marv:Marv;
private var _dexter:Dexter;
private var _cardX:Number;
private var _cardY:Number;
private var _firstCard:*;
private var _totalMatches:Number;
private var _currentMatches:Number;
public function MemoryGame()
{
_totalMatches = 2;
_currentMatches = 0;
createCards();
}
private function createCards():void
{
_cardX = 45;
_cardY = 31;
for(var i:Number = 0; i < 2; i++)
{
_card = new Card();
addChild(_card);
_marv = new Marv();
_card.setType(_marv);
_card.x = _cardX;
_card.y = _cardY;
_cardX += _card.width + 50;
_card.addEventListener(MouseEvent.CLICK, checkCards);
}
for(var j:Number = 0; j < 2; j++)
{
_card = new Card();
addChild(_card);
_dexter = new Dexter();
_card.setType(_dexter);
_card.x = _cardX;
_card.y = _cardY;
_cardX += _card.width + 50;
_card.addEventListener(MouseEvent.CLICK, checkCards);
}
}
private function checkCards(event:MouseEvent):void
{
event.currentTarget.removeEventListener(MouseEvent.CLICK, checkCards);
if(_firstCard == undefined)
{
_firstCard = event.currentTarget;
}
else if(String(_firstCard._type) == String(event.currentTarget._type))
{
trace("match!");
_firstCard = undefined;
_currentMatches ++;
if(_currentMatches >= _totalMatches)
{
trace("YOU WIN!!!!!!");
}
}
else
{
trace("wrong!");
_firstCard.gotoAndPlay("flipBack");
event.currentTarget.gotoAndPlay("flipBack");
_firstCard.addEventListener(MouseEvent.CLICK, checkCards);
event.currentTarget.addEventListener(MouseEvent.CLICK, checkCards);
_firstCard = undefined;
}
}
}
}
and then another actionscript file containing the information for a card
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Card extends MovieClip
{
public var _type:*;
public function Card()
{
this.buttonMode = true;
this.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(event:MouseEvent):void
{
if(this.currentFrame == 1)
{
this.play();
}
}
public function setType(type:*):void
{
_type = type;
loader_mc.addChild(_type);
}
}
}
the above cord is for loading the different cards movie clip images and puts them on the cards its the traces for if you have a match and once you have 2 matches its say that you have won, I'm going to look in to if you win a certain animation plays and once you have matched them all it has a special animation for the win of the hole game. the two file work together and load on to the main stage, using public and private functions to make the cards on the stage and in places with x and y co-ordinates and setting the size, along with if statement for determining on matches and wins along with variables to add on to the total count of wins, bellow are two screen dumps of the end result as you can see you start with four cards and once all all matched it outputs in the outputs window, i want to take the output and link in to an character animation. this is only a plan. i will be looking at this idea along side two others that i have storyboards for latter on.

EmoticonEmoticon