|
-
e.target problem
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:
PHP Code:
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
-
In the function name you have the value 'evt', so this should be the same inside the function.
PHP Code:
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");
}
}
-
thank you heaps, such a simple problem now i see it, but it had me stumped for ages. thanks
-
quotation marks in your conditions.
PHP Code:
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"); } }
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|