A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: HitTest - Tell an outside MovieClip to go to nextFrame()

  1. #1

    HitTest - Tell an outside MovieClip to go to nextFrame()

    I am trying to have a animated rollout sub-menu for a menu, and figured using the onClipEvent / hitTest code would work well. My dilemna is that I want the menu rollout to include a fading in of a full screen photo, so I added the animation of the photo to the menu's movieclip. However, once the photo fades in, it is then part of the MovieClip hitTest area, so it won't let the mouse "rollout" of the movieclip (as the mouse is always over the photo, which takes up the whole flash area).

    I came up with two possible solutions to solve the problem, but I need help with the coding:

    1. Is there a way to define the hit area specifically to be just the menu part of the MovieClip (and disregard the space area that the photo occupies)?

    or

    2. Move the Photo animation into it's own MovieClip and then use the hitTest code to call the photo's MovieClip and tell it to do the same thing. Is this possible? This seems the better solution if doable.

    Here's my attempt at coding this second option - but it doesn't work when I test it. Any ideas on how to make it work? The MovieClip of the photo animation has an instance name of "DiningRoom".

    Here is the (nonworking) code:

    onClipEvent (enterFrame) {
    if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
    this.nextFrame();
    } else {
    this.prevFrame();
    }
    }

    onClipEvent (enterFrame) {
    if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
    this.DiningRoom.nextFrame();
    } else {
    this.DiningRoom.prevFrame();
    }
    }



    Thanks for any help!

  2. #2
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    I would use your first solution...
    Using your movieclip as a button you can define a hit area with code.
    Create the hitArea you want, place it in your movie clip, set it's alpha to 0 and give it an instance name of hit_mc. Then with code do something like this:
    Code:
    this.hitArea(hit_mc);
    Let me know if that works for you.

  3. #3
    Thanks - this sounds like the solution I'd like to use -- however, I tried it, and it didn't seem to work - here is the SWF (use the lower right hand skip button to skip the animated intro):

    http://contagiousmedia.net/PearlStreet/Test/

    I created a box symbol for my hit area within the Dining Room button MovieClip timeline (which is defined as a MovieClip symbol), named it's instance "hit_mc" and then turned it's transparency to 0.

    Then, in the Dining Room MovieClip's instance's code, I added your line of code to the original ClipEvent code:

    onClipEvent (enterFrame) {
    if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
    this.hitArea(hit_mc);
    this.nextFrame();
    } else {
    this.prevFrame();
    }
    }

    This didn't work.. so I realized that perhaps I should have replaced the hitTest code with your suggested code, so then I tried this:

    onClipEvent (enterFrame) {
    if (this.hitArea(hit_mc)) {
    this.nextFrame();
    } else {
    this.prevFrame();
    }
    }

    Again, it didn't work... any suggestions? I'm kind of a novice at Actionscripting, so I'm not super clear as to where to add snippets of code. Thanks for your help!
    Last edited by Idelle; 05-09-2007 at 10:40 PM.

  4. #4
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    Okay I would suggest not using clipEvents...but without rewriting all of your code you can try this:

    Code:
    onClipEvent (enterFrame) {
         if (this.hitTest(hit_mc)) {
              this.nextFrame();
         } else {
         this.prevFrame();
         }
    }
    let me know how you make out
    [/code]

  5. #5
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    and depending on where you are adding your code, the timeline or on the actual movieclip, you may need something like:

    Code:
    onClipEvent (enterFrame) {
         if (this.hitTest(_parent.hit_mc)) {
              this.nextFrame();
         } else {
         this.prevFrame();
         }
    }

  6. #6

    Not working

    http://contagiousmedia.net/PearlStreet/Test2/

    I added your code to the Dining Room MovieClip instance:

    onClipEvent (enterFrame) {
    if (this.hitTest(hit_mc)) {
    this.nextFrame();
    } else {
    this.prevFrame();
    }
    }

    But, now it seems to be just running as soon as the movieclip appears in the timeline... and it just plays the movieclip regardless of where the mouse is located.

    I've uploaded the Flash file if you want to take a look:
    http://www.contagiousmedia.net/Pearl...ill_Denver.fla

    Thanks so much for helping... I really appreciate it!

  7. #7
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    This should get you started...
    I killed your onClipEvent stuff and wrote some new code.
    Note that this is just an example to fix your original problem.
    I would recommend setting some things up differently...such as having the section images in their own movieclip that gets controlled from your button events...you'll get more control that way.

    Let me know if you have any questions.

    http://www.jjsquared.com/flashkit/Pe...ll_Denver2.zip

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