I'll preface this by saying that, while I know a fair bit about C#, ASP.Net, HTML, etc... I am a mere pre-novice when it comes to AS3 scripting for Flash.

The basic idea of what I'm trying to do here is to create a simple children's mathematics game which runs through various mathematics excercises and uses coloured number tiles to 'fill-the-blanks'.

I've already figured out how to allow the user to pick up and move the tiles, how to ensure that the tiles can only be dropped on pre-determined targets and return them to their starting position if they aren't and how to allow a user to pick a tile up off the targets to drop them back where they started as well.

What I'm curious about is how to create a 'duplicate' of the number tile once it's been placed on a target where the duplicate appears in the original starting position of the chosen tile and has identical (enough) properties to the original that I can use it in the same way as the original (say the answer to a question is 11, they need to be able to select 2x "1" tiles).

I'm also curious as to what type of event I can use to 'register' that when the "1" tile is placed on a target square the value of "1" should be stored in a variable.

What I have so far is this:

var startX:Number;
var startY:Number;
var tile_Y:Number = 595;
var tile_0_X:Number = 5;
var tile_1_X:Number = 85;
var tile_2_X:Number = 165;
var tile_3_X:Number = 245;
var tile_4_X:Number = 325;
var tile_5_X:Number = 405;
var tile_6_X:Number = 485;
var tile_7_X:Number = 565;
var tile_8_X:Number = 645;
var tile_9_X:Number = 725;
var targ_1_X:Number = target_1.x;
var targ_1_Y:Number = target_1.y;
var targ_2_X:Number = target_2.x;
var targ_2_Y:Number = target_2.y;

tile_0.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
tile_0.addEventListener(MouseEvent.MOUSE_UP, dropIt);
tile_1.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
tile_1.addEventListener(MouseEvent.MOUSE_UP, dropIt);
tile_2.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
tile_2.addEventListener(MouseEvent.MOUSE_UP, dropIt);
tile_3.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
tile_3.addEventListener(MouseEvent.MOUSE_UP, dropIt);
tile_4.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
tile_4.addEventListener(MouseEvent.MOUSE_UP, dropIt);
tile_5.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
tile_5.addEventListener(MouseEvent.MOUSE_UP, dropIt);
tile_6.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
tile_6.addEventListener(MouseEvent.MOUSE_UP, dropIt);
tile_7.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
tile_7.addEventListener(MouseEvent.MOUSE_UP, dropIt);
tile_8.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
tile_8.addEventListener(MouseEvent.MOUSE_UP, dropIt);
tile_9.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
tile_9.addEventListener(MouseEvent.MOUSE_UP, dropIt);
function pickUp(event:MouseEvent):void {
    event.target.startDrag();
	event.target.parent.addChild(event.target);
	startX = event.target.x;
    startY = event.target.y;
}
function dropIt(event:MouseEvent):void {
    event.target.stopDrag();
	var myTargetName:String = "target_1";
    var myTarget:DisplayObject = getChildByName(myTargetName);
	var myTargetName2:String = "target_2";
    var myTarget2:DisplayObject = getChildByName(myTargetName2);
	if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget){
		event.target.x = targ_1_X;
		event.target.y = targ_1_Y;
	}
	else if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget2){
		event.target.x = targ_2_X;
		event.target.y = targ_2_Y;
	}
    else {
		if ((startX == targ_1_X && startY == targ_1_Y) || (startX == targ_2_X && startY == targ_2_Y))
		{
			var bName:String = event.target.name;
			if (event.target.dropTarget == null){
				if (bName == "tile_0")
				{
					startX = tile_0_X;
					startY = tile_Y;
				}
				if (bName == "tile_1")
				{
					startX = tile_1_X;
					startY = tile_Y;
				}
				if (bName == "tile_2")
				{
					startX = tile_2_X;
					startY = tile_Y;
				}
				if (bName == "tile_3")
				{
					startX = tile_3_X;
					startY = tile_Y;
				}
				if (bName == "tile_4")
				{
					startX = tile_4_X;
					startY = tile_Y;
				}
				if (bName == "tile_5")
				{
					startX = tile_5_X;
					startY = tile_Y;
				}
				if (bName == "tile_6")
				{
					startX = tile_6_X;
					startY = tile_Y;
				}
				if (bName == "tile_7")
				{
					startX = tile_7_X;
					startY = tile_Y;
				}
				if (bName == "tile_8")
				{
					startX = tile_8_X;
					startY = tile_Y;
				}
				if (bName == "tile_9")
				{
					startX = tile_9_X;
					startY = tile_Y;
				}
			}
			else if (event.target.dropTarget.parent == myTarget){
				event.target.x = targ_1_X;
				event.target.y = targ_1_Y;
			}
			else if (event.target.dropTarget.parent == myTarget2){
				event.target.x = targ_2_X;
				event.target.y = targ_2_Y;
			}
		}
		event.target.x = startX;
    	event.target.y = startY;
}
}
tile_0.buttonMode = true;
tile_1.buttonMode = true;
tile_2.buttonMode = true;
tile_3.buttonMode = true;
tile_4.buttonMode = true;
tile_5.buttonMode = true;
tile_6.buttonMode = true;
tile_7.buttonMode = true;
tile_8.buttonMode = true;
tile_9.buttonMode = true;

As you can see, for someone who's never touched AS3 before I'm not doing TOO badly to start but I'm somewhat stuck at this point.

Thanks in advance for your assistance :twisted:

Edit: I had a choice between putting this in Graphics and Multimedia or Game Design as it would fit in either but I'm surprised there isn't a Flash forum considering there's forums for virtually every other coding environment.

Member Avatar for rajarajan2017

As like AS2, In AS3 we didn't have the duplicateMovieClip, Instead you just create the movieclip instance with the Linkage Identifier in the library and add it on the stage number of times you want with proper positionings. You drop on a particular movieclip you can make a "HIT test" on the clip.

As like AS2, In AS3 we didn't have the duplicateMovieClip, Instead you just create the movieclip instance with the Linkage Identifier in the library and add it on the stage number of times you want with proper positionings. You drop on a particular movieclip you can make a "HIT test" on the clip.

Thanks for that, I think I already read up a bit on the hit test methods so I guess I'll have to look more into creating additional clips and disposing of them as they're no longer needed for what I want to do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.