A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Eventlistener to sprite in loop?

  1. #1
    Junior Member
    Join Date
    Sep 2007
    Posts
    8

    Eventlistener to sprite in loop?

    Ok, I have a loop which loops out 10 empty movie clips and then adds 10 sprites inside those movieclips.

    What I want to do is to change the alpha of the sprite I hover. But since I can't add eventlistener to the sprite how can change it's alpha?

    Can't just use:

    PHP Code:
    private function hoverSprite(event:MouseEvent)
    {
    spritename.alpha 0.5;

    Because then only the last looped sprite will change alpha then.

  2. #2
    Ronze Ronze's Avatar
    Join Date
    Oct 2002
    Location
    Copenhagen, Denmark
    Posts
    185
    Hey

    Fortunatly the event carries the event target - that's a path to the object that dispatched the event. So in your code, just do like this:

    Code:
    private function hoverSprite(event:MouseEvent) 
    { 
          event.target.alpha = 0.5; 
    }
    Should work, but haven't tested it
    --- Ronze ---

  3. #3
    Junior Member
    Join Date
    Sep 2007
    Posts
    8
    Quote Originally Posted by Ronze
    Hey

    Fortunatly the event carries the event target - that's a path to the object that dispatched the event. So in your code, just do like this:

    Code:
    private function hoverSprite(event:MouseEvent) 
    { 
          event.target.alpha = 0.5; 
    }
    Should work, but haven't tested it

    Ok, alpha was an bad example. Because I can just change the alpha of the movieclip. What I really need to do is to change the sprites fill colour, that's why I need to acces the sprite itself and not the movieclip. Sorry

  4. #4
    Ronze Ronze's Avatar
    Join Date
    Oct 2002
    Location
    Copenhagen, Denmark
    Posts
    185
    Hmmm... I don't understand. The sprites inside the different movieclips must have the same name, as you make them in a loop.

    Therefore it's just to say:

    Code:
    event.target.spritename
    to target the sprite. Here spritename is offcourse the name you give it in the loop. If you still have questions, post your code.
    --- Ronze ---

  5. #5
    Junior Member
    Join Date
    Sep 2007
    Posts
    8
    Quote Originally Posted by Ronze
    Hmmm... I don't understand. The sprites inside the different movieclips must have the same name, as you make them in a loop.

    Therefore it's just to say:

    Code:
    event.target.spritename
    to target the sprite. Here spritename is offcourse the name you give it in the loop. If you still have questions, post your code.

    Thanks for the help. I kinda missunderstood a lot of stuff ^^ That's why you got confused when I tried to explain. I think I solved it now. Thanks again

  6. #6
    Ronze Ronze's Avatar
    Join Date
    Oct 2002
    Location
    Copenhagen, Denmark
    Posts
    185
    no probs :-O
    --- Ronze ---

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