Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-28-2009, 04:43 PM   #1
dimijin
Senior Member
 
Join Date: Jun 2009
Posts: 247
Default hitTestPoint & mouse X & Y ???

Hey guys, I'm having problems getting a hitTestPoint to run properly. It keeps throwing the same error no matter what I try.

1120: Access of undefined property mouseX.

I need the mc (thumbs) to fade in and once it has faded check to see if the mouse is over it in order to trigger other code. I need to run the test as soon as the tween is over regardless if there is/isn't a mouse event, which is why you'll see my attempts at using the ENTER_FRAME event.

Here is the offending code:

ActionScript Code:
TweenLite.to(thumbs, 1.5, {alpha: 1, onComplete:checkMouse});             function checkMouse():void {     menu.addEventListener(Event.ENTER_FRAME, hitTest);                     function hitTest(event:Event):void     {         if(menu.hitTestPoint(mouseX, mouseY, true))         {             trace("working");         }     } }

What am I doing wrong ?
dimijin is offline   Reply With Quote
Old 07-28-2009, 04:46 PM   #2
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,909
Send a message via Skype™ to henke37
Default

For one thing, hitTestPoint uses the stage coordinate system, not the local coordinate system of the object.
henke37 is offline   Reply With Quote
Old 07-29-2009, 02:05 AM   #3
dimijin
Senior Member
 
Join Date: Jun 2009
Posts: 247
Default

henke37...

Thanks for the input. I'm trying to digest that information but I'm kind of confused as I am super new to actionscript and this is the first time I've ever used any hit tests. If you could elaborate a bit more on this subject I would really appreciate it.

I modified the code from the following example and it seems like he got it to work somehow:

http://www.flepstudio.org/forum/tuto...ipt-3-0-a.html

Do you have any suggestions on how to accomplish this?
dimijin is offline   Reply With Quote
Old 07-29-2009, 02:17 AM   #4
dimijin
Senior Member
 
Join Date: Jun 2009
Posts: 247
Default

Would applying the listener to the stage instead of the menu object theoretically work?

ActionScript Code:
TweenLite.to(thumbs, 1.5, {alpha: 1, onComplete:checkMouse});             function checkMouse():void {     stage.addEventListener(Event.ENTER_FRAME, hitTest);                     function hitTest(event:Event):void     {         if(menu.hitTestPoint(mouseX, mouseY, true))         {             trace("working");         }     } }
dimijin is offline   Reply With Quote
Old 07-29-2009, 02:21 AM   #5
UncleNinja
I love noogies.
 
UncleNinja's Avatar
 
Join Date: Mar 2009
Location: Georgia, USA
Posts: 786
Default

Looks like you're trying to do the equivalent of a rollover or rollout eventListener in your enterFrame. Why not do that?

ActionScript Code:
TweenLite.to(thumbs, 1.5, {alpha: 1, onComplete:addMenuListeners});             function addMenuListeners() {     menu.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler); } function mouseOverHandler(e:MouseEvent){     trace("working"); }
__________________
-UncleNinja on Twitter

ActionScript Hints - a revolutionary wiki dedicated to helping Flash developers
UncleNinja is offline   Reply With Quote
Old 07-29-2009, 04:48 AM   #6
dimijin
Senior Member
 
Join Date: Jun 2009
Posts: 247
Default

UncleNinja...

Thanks for your comments.

In the class file where this code lives there actually is a rollover & mouse_over assigned to the menu mc which trigger the same method that I want the hitTest to trigger. Basically, I want the hitTest to do the same exact thing that the rollover does but I want it to do it via a hitTestPoint instead.

The rollover tweens brightness, saturation, alpha and changes visibility of many child objects in order to give the user some visual feedback that the menu has been activated and they're currently focusing on it.

I need the hitTest to run a check on the very first time the swf is loaded and then deactivate itself letting the rollover handle it from that point on.

The need for the hitTest becomes necessary if the mouse is over the menu object while the swf is being loaded. If this happens, and a rollover is being listened for, the rollover's method will not trigger since a rollover event hasn't occured. This means that even though the mouse is over the menu object, the menu will appear as if it hasn't been activated and is not currently in focus.

If I use a mouse_over event and the mouse is over the menu after the swf initializes, it still won't automatically run the method responsible for adding visual focus to the menu. It will work if the user moves the mouse slightly but having the menu visually show that your focusing on it at all times is my goal.

If I can get the hitTest to work properly it wont rely on any mouse events and will check on the first load to see if the mouse is over the menu and call the proper method for adding visual focus if it is. The hitTest would insure the menu reacts the same all the time.

Any thoughts?

Thanks again.

Last edited by dimijin; 07-29-2009 at 05:16 AM.
dimijin is offline   Reply With Quote
Old 07-29-2009, 11:15 AM   #7
UncleNinja
I love noogies.
 
UncleNinja's Avatar
 
Join Date: Mar 2009
Location: Georgia, USA
Posts: 786
Default

Oh okay.
I tested this code and it worked fine.
ActionScript Code:
TweenLite.to(thumbs, 1.5, {alpha: 1, onComplete:checkMouse});             function checkMouse():void {     stage.addEventListener(Event.ENTER_FRAME, hitTest);    } function hitTest(event:Event):void {     if(menu.hitTestPoint(mouseX, mouseY, true))     {         trace("working");     } }
if you are still getting that error, try importing flash.display.DisplayObject.
mouseX is a property of that.

By the way, it is probably a good idea to avoid putting functions inside other functions so I changed your code
__________________
-UncleNinja on Twitter

ActionScript Hints - a revolutionary wiki dedicated to helping Flash developers

Last edited by UncleNinja; 07-29-2009 at 11:21 AM.
UncleNinja is offline   Reply With Quote
Old 07-29-2009, 11:40 AM   #8
Mazoonist
Site Contributor
 
Mazoonist's Avatar
 
Join Date: Jun 2006
Posts: 3,160
Send a message via AIM to Mazoonist
Default

It would be nice to see the source (or files) on this.
__________________
My Tutorials * My Website
Mazoonist is offline   Reply With Quote
Old 07-29-2009, 05:11 PM   #9
dimijin
Senior Member
 
Join Date: Jun 2009
Posts: 247
Default

UncleNinja...

I figured it out!!!!

The issue was due to me not assigning the mouseX & Y properties to an instance of the stage because of the code being used in an imported class file.

Here's what I did in order to make it work.

I passed an instance of the stage from the document class to the constructor of the imported class where I'm using the hitTest. I then declared a private var called theStage and set it equal to the stage instance inside the constructor. When I reference the mouseX & Y properties I do so successfully by using theStage.mouseX etc.

Here's the code:

..............document class..............
ActionScript Code:
package photoGallery {     import flash.display.*;         public class PhotoGalleryDocument extends MovieClip     {         public var photoView:PhotoGalleryView;                                                     public function PhotoGalleryDocument()         {             photoView = new PhotoGalleryView(stage, menu_mc, thumbs_mc);                            }           } }

.................class file................
ActionScript Code:
package photoGallery {     import mvc.View;     import flash.display.*;     import flash.events.*;     import gs.TweenLite;     import gs.easing.*;             public class PhotoGalleryView extends View     {         private var theStage:Stage;                         private var menu:MovieClip;         private var thumbs:MovieClip;                 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /*    CONSTRUCTOR         */ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////                 public function PhotoGalleryView(s:Stage, m:MovieClip, t:MovieClip )         {                   theStage = s;             menu = m;             thumbs = t;         }

.................code using theStage inside class file................
ActionScript Code:
TweenLite.to(thumbs, 1.5, {alpha: 1, onComplete:checkMouse});             function checkMouse():void {     theStage.addEventListener(Event.ENTER_FRAME, hitTest);    }             function hitTest(event:Event):void {     if(menu.hitTestPoint(theStage.mouseX, theStage.mouseY, true))     {         menuOver(new MouseEvent("rollOver"));         theStage.removeEventListener(Event.ENTER_FRAME, hitTest);     } }

THANK YOU SO MUCH FOR YOUR HELP!

Troubleshooting with you helped me figure this out.

Last edited by dimijin; 07-29-2009 at 05:26 PM.
dimijin is offline   Reply With Quote
Old 07-29-2009, 05:14 PM   #10
dimijin
Senior Member
 
Join Date: Jun 2009
Posts: 247
Default

Mazoonist...

Hey man.

I was just trying to keep the focus on the problem code instead of showing all 700 lines of code. Attempting to make it easier on you guys when trying to decipher what I have going on.
dimijin is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:23 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.