---------------------------------------------------------------------------------------------------------------------
READ MORE:
DOWNLOAD SOURCE FILE:
----------------------------------------------------------------------------------------------------------------------
COPY AND PASTE BELOW CODE
----------------------------------------------------------------------------------------------------------------------
//MAKE 6 COPIES OF BLACK BOX SET CLASS NAME "BlackBox"
// MAKE GREEN BALL MOVIE CLIP SET CLASS NAME "GreenBall"
// MAKE RED BALL MOVIE CLIP SET CLASS NAME "RedBall"
//http://code.tutsplus.com/tutorials/as3-101-variables-basix--active-798
import flash.events.MouseEvent;
import flash.display.MovieClip;
var targetBox:uint = Math.ceil(Math.random() * 6);
//TRACE METHOD TELL US WHICH BOX HAS RED BALL
trace("looking for box: " + targetBox);
box1.addEventListener(MouseEvent.CLICK, boxClickHandler);
box2.addEventListener(MouseEvent.CLICK, boxClickHandler);
box3.addEventListener(MouseEvent.CLICK, boxClickHandler);
box4.addEventListener(MouseEvent.CLICK, boxClickHandler);
box5.addEventListener(MouseEvent.CLICK, boxClickHandler);
box6.addEventListener(MouseEvent.CLICK, boxClickHandler);
box1.targetId = 1;
box2.targetId = 2;
box3.targetId = 3;
box4.targetId = 4;
box5.targetId = 5;
box6.targetId = 6;
function boxClickHandler(event:MouseEvent):void{
var clickedBox:MovieClip = event.target as MovieClip;
clickedBox.removeEventListener(MouseEvent.CLICK, boxClickHandler);
if(targetBox == clickedBox.targetId)
boxFound(clickedBox);
else
wrongBox(clickedBox);
}
function boxFound(clickedBox:MovieClip):void{
var redBall:RedBall = new RedBall();
addChild(redBall);
redBall.x = clickedBox.x;
redBall.y = clickedBox.y;
}
function wrongBox(clickedBox:MovieClip):void{
var greenBall:GreenBall = new GreenBall();
addChild(greenBall);
greenBall.x = clickedBox.x;
greenBall.y = clickedBox.y;
}
----------------------------------------------------------------------------------------------------------------------
UPPER CODE WITH ENTER FRAME FUNCTION
COPY AND PASTE BELOW CODE
----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
//MAKE 6 COPIES OF BLACK BOX SET CLASS NAME "BlackBox"
// MAKE GREEN BALL MOVIE CLIP SET CLASS NAME "GreenBall"
// MAKE RED BALL MOVIE CLIP SET CLASS NAME "RedBall"
//http://code.tutsplus.com/tutorials/as3-101-variables-basix--active-798
import flash.events.MouseEvent;
import flash.display.MovieClip;
var targetBox:uint = Math.ceil(Math.random() * 6);
//TRACE METHOD TELL US WHICH BOX HAS RED BALL
trace("looking for box: " + targetBox);
box1.addEventListener(Event.ENTER_FRAME, boxClickHandler);
box2.addEventListener(Event.ENTER_FRAME, boxClickHandler);
box3.addEventListener(Event.ENTER_FRAME, boxClickHandler);
box4.addEventListener(Event.ENTER_FRAME, boxClickHandler);
box5.addEventListener(Event.ENTER_FRAME, boxClickHandler);
box6.addEventListener(Event.ENTER_FRAME, boxClickHandler);
box1.targetId = 1;
box2.targetId = 2;
box3.targetId = 3;
box4.targetId = 4;
box5.targetId = 5;
box6.targetId = 6;
function boxClickHandler(event:Event):void{
var clickedBox:MovieClip = event.target as MovieClip;
clickedBox.removeEventListener(MouseEvent.CLICK, boxClickHandler);
if(targetBox == clickedBox.targetId)
boxFound(clickedBox);
else
wrongBox(clickedBox);
}
function boxFound(clickedBox:MovieClip):void{
var redBall:RedBall = new RedBall();
addChild(redBall);
redBall.x = clickedBox.x;
redBall.y = clickedBox.y;
}
function wrongBox(clickedBox:MovieClip):void{
var greenBall:GreenBall = new GreenBall();
addChild(greenBall);
greenBall.x = clickedBox.x;
greenBall.y = clickedBox.y;
}
--------------------------------------------------------------------------------------------------------------------------
ENTER FRAME FUNCTION BOX ARRAY CODE
http://flashcollege.blogspot.co.uk/2014/11/next-frame-function-in-as3.html
1- BELOW CODE USE IN TWO WAYS MEAN FOLLOW THE UPPER METHOD WITH CLASS
2- OR MAKE 6 INDIVIDUAL MOVIE CLIPS IN DIFFERENT COLORS NO NEED CLASS
AND GIVE INSTANCE NAME box1,box2,box3,box4,box5,box6 SIZE = H;100 X W:100
--------------------------------------------------------------------------------------------------------------------------
//MAKE 6 COPIES OF BLACK BOX SET CLASS NAME "BlackBox"
// MAKE GREEN BALL MOVIE CLIP SET CLASS NAME "GreenBall"
// MAKE RED BALL MOVIE CLIP SET CLASS NAME "RedBall"
//http://code.tutsplus.com/tutorials/as3-101-variables-basix--active-798
import flash.events.MouseEvent;
import flash.display.MovieClip;
var targetBox:uint = Math.ceil(Math.random() * 6);
//TRACE METHOD TELL US WHICH BOX HAS RED BALL
trace("looking for box: " + targetBox);
var BoxArray = new Array(box1,box2,box3,box4,box5,box6);
for (var i:int = 0; i < BoxArray.length; i++) {
BoxArray[i].addEventListener(Event.ENTER_FRAME,BoxEnterFrameFunction);
}
box1.targetId = 1;
box2.targetId = 2;
box3.targetId = 3;
box4.targetId = 4;
box5.targetId = 5;
box6.targetId = 6;
function BoxEnterFrameFunction(event:Event):void{
var clickedBox:MovieClip = event.target as MovieClip;
clickedBox.removeEventListener(MouseEvent.CLICK,BoxEnterFrameFunction);
if(targetBox == clickedBox.targetId)
boxFound(clickedBox);
else
wrongBox(clickedBox);
}
function boxFound(clickedBox:MovieClip):void{
var redBall:RedBall = new RedBall();
addChild(redBall);
redBall.x = clickedBox.x;
redBall.y = clickedBox.y;
}
function wrongBox(clickedBox:MovieClip):void{
var greenBall:GreenBall = new GreenBall();
addChild(greenBall);
greenBall.x = clickedBox.x;
greenBall.y = clickedBox.y;
}
EmoticonEmoticon