A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: e.target problem

  1. #1
    Member
    Join Date
    Jun 2009
    Posts
    75

    Question 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_DOWNclickedEvent);
    picture2.addEventListener(MouseEvent.MOUSE_DOWNclickedEvent);

    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

  2. #2
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    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");
    }


  3. #3
    Member
    Join Date
    Jun 2009
    Posts
    75
    thank you heaps, such a simple problem now i see it, but it had me stumped for ages. thanks

  4. #4
    Member
    Join Date
    Oct 2009
    Location
    Toronto, Canada
    Posts
    30
    quotation marks in your conditions.
    PHP Code:
    picture.addEventListener(MouseEvent.MOUSE_DOWNclickedEvent); 
    picture2.addEventListener(MouseEvent.MOUSE_DOWNclickedEvent); 

    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center