A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [F8] Checking 100 MC's if mouseOver

  1. #1
    Member
    Join Date
    May 2005
    Location
    Switzerland
    Posts
    85

    [F8] Checking 100 MC's if mouseOver

    I have a "table" with 100 movieclips on my stage. These movie clips are 'fake' buttons and have another movie clip embedded which contains a input text field. When I click on one of those movieclips, the input text field gets activated, thus enabling me to input a number there.
    (Btw, this is for a game for young kids, who need to practice the numbers 1 - 100. The script then checks the number that was input, as well as if the number was input into the right box...)

    The code fragment, used on frame one of the stage to set everything up, looks like this ("box.." being the name of those mc's):

    Code:
    for ( var i:Number = 1; i <= 100; i++ ) {
    	_root["box"+i].onMouseDown = function():Void {
    		if ( this.hitTest( _root._xmouse, _root._ymouse, true ) ) {
    			this.inputField._visible = true;
    			trace("clicked on "+this._name)
    		}
    	};
    }
    Now, I wonder if there is an easier way to check which movieclip got clicked without having all 100 movieclips check the status. Can I add any action to the mouse, which will check which clips it hits when mouseDown occurs?

    Unfortunately I can't use the
    Code:
    movieclip.onRelease = function()
    as that way the MC's get totally converted into a button and I can't input any text into the text field anymore.

    Thanks for any ideas or help.

    Cheers
    ----

  2. #2
    Ninja Rider Jhonte's Avatar
    Join Date
    Sep 2004
    Location
    Uppsala,Sweden
    Posts
    253
    use onPress instead?

    Code:
    _root["box"+i].onPress = function():Void {
    			this.inputField._visible = true;
    			trace("clicked on "+this._name)
    };
    Show me the way to the next whiskeybar ...

  3. #3
    Member
    Join Date
    May 2005
    Location
    Switzerland
    Posts
    85
    Thanks Jhonte,
    but that won't do the trick.

    Both, onPress and onRelease, are button-events, thus turning the MC into a button.
    ----

  4. #4
    Island Boy
    Join Date
    Apr 2006
    Posts
    655
    is the code you have above not working? if you have that code int eh first frame and it sets up the MC that way then it should not loop through that function again. the hit tests are already setup and attached to the MC (button). so when you click in anyone fo them it just fires off the the hitTest function for that MC only.

  5. #5
    Member
    Join Date
    May 2005
    Location
    Switzerland
    Posts
    85
    The code is working fine. It's just not very efficient as when mouseDown occurs all 100 movies check if they are hit by the mouse.

    I'm just trying to figure out a way to optimize this one.
    ----

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    use onPress, as Jhonte suggested, and useHandCursor set to false. You can also use a hidden button in your clips.

    gparis

  7. #7
    Member
    Join Date
    May 2005
    Location
    Switzerland
    Posts
    85
    Thanks for the tip, gparis

    Thing is, as soon as I use onPress or onRelease I can't write into the input text field anymore. No matter if I turn the appearance of the cursor.

    Anyway, I guess I just keep it the inefficient way, unless I can figure out some work around.
    ----

  8. #8
    Island Boy
    Join Date
    Apr 2006
    Posts
    655
    goto http://www.gotoandlearn.com/ and look for scrolling thumbnail panel. There is a procedure he uses in there that does what you are trying to do. The tutorial itself is not what you want but the procedure in which he does it will maybe give you an idea of what you need to do. though he uses buttons instead of MCs but it should work the same.

  9. #9
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Quote Originally Posted by peter_u
    Thanks for the tip, gparis

    Thing is, as soon as I use onPress or onRelease I can't write into the input text field anymore. No matter if I turn the appearance of the cursor.

    Anyway, I guess I just keep it the inefficient way, unless I can figure out some work around.
    Not if your action comes from an invisible button inside the MC.
    That's how i usually do it.

    gparis

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