dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Reusing Functions on more than one movie clip

  1. #1
    Senior Member
    Join Date
    Jul 2000
    Posts
    373

    Reusing Functions on more than one movie clip

    I'm doing a filmstrip animation and each frame of the strip has a small pic on it and using TweenLite, I'm making it expand and contract on mouse rollover and rollout. That's not the problem. Since it's basically the same function, I don't want to have to write it for all 16 frames. I thought I'd try 'this' but that doesn't work on AS3. So I'm trying to find a solution that does. Here's my code (for one frame of the movie....in this case, the eighth).:

    import gs.TweenLite;
    fsAnim.filmstrip_mc.photo8_mc.addEventListener(Mou seEvent.MOUSE_OVER, photoOver);
    fsAnim.filmstrip_mc.photo8_mc.addEventListener(Mou seEvent.MOUSE_OUT, photoOut);
    function photoOver(evt:MouseEvent):void {
    fsAnim.stop();
    TweenLite.to(fsAnim.filmstrip_mc.photo8_mc, .5, {scaleX:1.5, scaleY:1.5});
    }
    function photoOut(evt:MouseEvent):void {
    fsAnim.play();
    TweenLite.to(fsAnim.filmstrip_mc.photo8_mc, .5, {scaleX:1, scaleY:1});
    }
    Adam Bell
    dzign@datatv.com
    --
    Over 90% of all websites
    suck......
    Join the minority.

  2. #2
    Señor Member Mavrisa's Avatar
    Join Date
    Oct 2005
    Location
    Canada
    Posts
    506
    e.target would be what you're looking for.

    function photoOver(evt:MouseEvent):void {
    e.target.parent.parent.stop();
    TweenLite.to(e.target, .5, {scaleX:1.5, scaleY:1.5});
    }
    function photoOut(evt:MouseEvent):void {
    e.target.parent.parent.play();
    TweenLite.to(e.target, .5, {scaleX:1, scaleY:1});
    }

    you can add this function as a listener to as many objects provided they all have the same structure as fsAnim (that is, the base clip must have a child, which has another child, which is the one the event listener is used on). The reason for the same structure is the .parent.parent part. If the movieclip processing the event didn't have 2 parents, the code would throw an error.

    Hope that helps,
    Mavrisa
    Haikus are easy
    But sometimes they don't make sense
    Refrigerator

  3. #3
    Senior Member
    Join Date
    Jul 2000
    Posts
    373
    I tried that but it came back with four errors of undefined property of e.target. Here's what I got now.

    import gs.TweenLite;
    fsAnim.filmstrip_mc.photo1_mc.addEventListener(Mou seEvent.MOUSE_OVER, photoOver);
    fsAnim.filmstrip_mc.photo1_mc.addEventListener(Mou seEvent.MOUSE_OUT, photoOut);
    fsAnim.filmstrip_mc.photo2_mc.addEventListener(Mou seEvent.MOUSE_OVER, photoOver);
    fsAnim.filmstrip_mc.photo2_mc.addEventListener(Mou seEvent.MOUSE_OUT, photoOut);
    function photoOver(evt:MouseEvent):void {
    fsAnim.stop();
    e.target.parent.parent.stop();
    TweenLite.to(e.target, .5, {scaleX:1.5, scaleY:1.5});
    }
    function photoOut(evt:MouseEvent):void {
    fsAnim.play();
    e.target.parent.parent.play();
    TweenLite.to(e.target, .5, {scaleX:1, scaleY:1});
    }
    Adam Bell
    dzign@datatv.com
    --
    Over 90% of all websites
    suck......
    Join the minority.

  4. #4
    Señor Member Mavrisa's Avatar
    Join Date
    Oct 2005
    Location
    Canada
    Posts
    506
    Ah. Sorry, evt.target would be the variable you would need to use. It's whatever variable you have in your function's brackets.
    Haikus are easy
    But sometimes they don't make sense
    Refrigerator

Tags for this Thread

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