Skip to main content
Inspiring
September 14, 2007
Answered

HitTest on movieclip

  • September 14, 2007
  • 1 reply
  • 703 views
Hi, Beginner and trying to get a feel for flash. I’m extremely competent Lingo programmer but finding Flash extremely frustrating.

I have an external .as script that imports successfully. I put a mouseListerner inside this .as and I want to detect the mouseDown within a movieClip I’ve placed on the stage that has an Instance name of pageA.

I've attached code so can someone explain where I’m going wrong please.

Thanks in advance for any help.Simon.
This topic has been closed for replies.
Correct answer smartino
If your _root.attachMovie line works for you then you shouldn't have any problems.
Modify your code to include;
if (beenHit ) {
_root.attachMovie("hotspotlink", "HS" + _hitsCounter, HotSpot._hitDepth++, {_x:_root._xmouse, _y:_root._ymouse});
}

then the new MC will only be added when you click on pageA. But make sure you have the 'Export for ActionScript' checked for the movieclip hotspotlink.

I tried this setup from the timeline and it works fine.

Hi Sivakanesh, thanks for helping with this. When reading your last thread I noticed i didn't have _root for my mouse positions. I traced them and they were undefined on my function! It looks like this and it works...

_MouseClickListen.onMouseDown = function(){
var beenHit = (_root.pageA.hitTest(_root._xmouse, _root._ymouse, true));
if (beenHit ) {
_root.attachMovie("hotspotlink", "HS" + _hitsCounter, HotSpot._hitDepth++, {_x:_root._xmouse, _y:_root._ymouse});
}
updateAfterEvent();
}
Mouse.addListener(_MouseClickListen);


Coming from a Director Lingo background i'm finding it difficult when to use _root and the like. I hope I get a handle on it soon though!

Cheers Simon.

1 reply

Known Participant
September 14, 2007
You have the right idea, but you must always declare your variables properly.
add this line above your function;
var _MouseClickListen:Object = new Object();

If you run the code, it should work.
smartinoAuthor
Inspiring
September 14, 2007
Thanks Sivakanesh I already have this in my .as file...

private var _MouseClickListen:Object = new Object();

I have a setup of variables and constants at the beginning of the movie.

Is there something wrong with this?

Si.
Known Participant
September 14, 2007
Unless you are writing classes you cannot use the keyword private.
Make your line var _MouseClickListen:Object = new Object(); then give it a try.

Also note that you are missing a ')' in the line var beenHit = (_root.pageA.hitTest(_xmouse, _ymouse, true);. I assume its a typo when you pasted it here. It needs to be var beenHit = (_root.pageA.hitTest(_xmouse, _ymouse, true));.

Other these two the code works fine.
Siva