6 Replies Latest reply on Sep 17, 2007 3:02 AM by smartino

    HitTest on movieclip

    smartino Level 1
      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.
        • 1. Re: HitTest on movieclip
          Sivakanesh
          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.
          • 2. HitTest on movieclip
            smartino Level 1
            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.
            • 3. Re: HitTest on movieclip
              Sivakanesh Level 1
              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
              • 4. Re: HitTest on movieclip
                smartino Level 1
                I'm writing classes and correct that was a typo from cutting and pasting.

                I've taken the code and placed it in the main timeline in a test movie and it works.

                I can attachmovies all over the stage like this...

                _root.attachMovie("hotspotlink", "HS" + _hitsCounter, HotSpot._hitDepth++, {_x:_root._xmouse, _y:_root._ymouse});

                ...that works, but i want it to only happen on the movieClip area!

                • 5. Re: HitTest on movieclip
                  Sivakanesh Level 1
                  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.
                  • 6. HitTest on movieclip
                    smartino Level 1
                    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.