1 Replies - 810 Views - Last Post: 21 August 2010 - 01:31 PM

#1 Guest_Paige*


Reputation:

simple loop problems

Posted 18 August 2010 - 11:29 AM

im in a struggle to figure this out

i have this code to have a user selected two different words with different
font styles to match them. they drag the two words into a box and then
they have a message come up saying "good job" or "try again"...however, i
can't get the message to appear please help me please.


code:
import flash.events.MouseEvent;

stop();

tryagain.visible = false;
goodjob.visible = false;
//nextbtn.visible = false;
target1.visible = true;

//nextbtn.addEventListener(MouseEvent.MOUSE_DOWN, nextframe);
l1.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
l1.addEventListener(MouseEvent.MOUSE_UP, dropIt);
r1.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
r1.addEventListener(MouseEvent.MOUSE_UP, dropIt);
l2.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
l2.addEventListener(MouseEvent.MOUSE_UP, dropIt);
r2.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
r2.addEventListener(MouseEvent.MOUSE_UP, dropIt);
l3.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
l3.addEventListener(MouseEvent.MOUSE_UP, dropIt);
r3.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
r3.addEventListener(MouseEvent.MOUSE_UP, dropIt);

function pickUp(event:MouseEvent):void {
event.target.startDrag(true);
}

var counter:Number = 0;
var i = 0;
//array of left items
var rArray:Array = new Array(r1, r2, r3, r4, r5, r6, r7, r8, r9);
//array of the right items
var lArray:Array = new Array(l1, l2, l3, l4, l5, l6, l7, l8, l9);


function dropIt(event:MouseEvent):void {
event.target.stopDrag();
i = 0;

for (var i: int = 0; i < 3; i++){

if ( lArray[i].hitTestObject(target1)){
counter++;
}
if ( rArray[i].hitTestObject(target1)){
counter++;
}
if (counter == 2){
if(l1.hitTestObject(target1) == r2.hitTestObject(target1) || 
l2.hitTestObject(target1) == r1.hitTestObject(target1) || 
l3.hitTestObject(target1) == r3.hitTestObject(target1)) 
{
goodjob.visible = true;
nextbtn.visible = true;
} else {
tryagain.visible = true;
}

}
}
}

l1.buttonMode = true;
r1.buttonMode = true;
l2.buttonMode = true;
r2.buttonMode = true;
l3.buttonMode = true;
r3.buttonMode = true;



Edited by macosxnerd101: Welcome to DIC! :) Please, :code:.

Is This A Good Question/Topic? 0

Replies To: simple loop problems

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: simple loop problems

Posted 21 August 2010 - 01:31 PM

I take it you put a marker down where the object should be hitting? Add this code
if (event.currentTarget.hitTestObject(getChildByName("Your Marker Name")))
{
trace("IT WORKED");
}


To see if it is registering properly. Just make sure you change the name in the brackets to the name of your marker. Additionally, make sure you place it in the dropIt function.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1