-
[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
----
-
Ninja Rider
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 ...
-
Thanks Jhonte,
but that won't do the trick.
Both, onPress and onRelease, are button-events, thus turning the MC into a button.
----
-
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.
-
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.
----
-
use onPress, as Jhonte suggested, and useHandCursor set to false. You can also use a hidden button in your clips.
gparis
-
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.
----
-
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|