;

PDA

Click to See Complete Forum and Search --> : e.target problem


Jbard
10-07-2009, 05:44 AM
Hi
i am trying to make a photo gallery so when people click on a thumbnail it expands to full screen, my problem is i have lots of pictures and i want to determine which one has been clicked. i thought i would use the e.target in a simple if statement like this:

picture.addEventListener(MouseEvent.MOUSE_DOWN, clickedEvent);
picture2.addEventListener(MouseEvent.MOUSE_DOWN, clickedEvent);

function clickedEvent(evt:MouseEvent):void{
if(e.target.name == picture){
trace("picture one is clicked");
}
else if(e.target.name == picture2){
trace("picture two is clicked");
}
}



in this picture one and two are both on the stage with instance names of picture and picture2.
i have no idea why this isn't working, i have used e.target before with no problems.
any help would be great. thanks

ilike2
10-07-2009, 09:10 AM
In the function name you have the value 'evt', so this should be the same inside the function.

function clickedEvent(evt:MouseEvent):void{
if(evt.target.name == picture){
trace("picture one is clicked");
}
else if(evt.target.name == picture2){
trace("picture two is clicked");
}
}

Jbard
10-07-2009, 07:43 PM
thank you heaps, such a simple problem now i see it, but it had me stumped for ages. thanks

Yasky
10-08-2009, 01:01 AM
quotation marks in your conditions.
picture.addEventListener(MouseEvent.MOUSE_DOWN, clickedEvent);
picture2.addEventListener(MouseEvent.MOUSE_DOWN, clickedEvent);

function clickedEvent(evt:MouseEvent):void{
if(evt.target.name == "picture"){
trace("picture one is clicked");
}
else if(evt.target.name == "picture2"){
trace("picture two is clicked");
}
}