Groups | Blog | Home
all groups > flash actionscript > may 2004 >

flash actionscript : Selecting a movieClip?


R_Anthony
5/10/2004 11:29:21 PM
Can someone explain how to do the following?
I have a series of movie clips on the stage, that contain images. I want to
select the clip using the mouse. Than using a button I want to capture the
movie clip name/ID and store it in an array, to be used in another part of the
movie. My question is how do I select the movie clip and retrive its name?
Any help would be great!
kglad
5/11/2004 12:43:00 AM
the following will store the movieclip name of any movieclip that's clicked.
if you want to remove that movieclip if your button's not pressed within a
certain timelimit or before another button or movieclip is clicked you'll need
to handle that part of the code or let us know how you want to decide when a
movieclip is selected.

storeA= new Array();
someListener = new Object();
someListener.onMouseDown = function() {
for (obj in _root) {
if (typeof (_root[obj]) == "movieclip") {
if (_root[obj].hitTest(_root._xmouse, _root._ymouse)) {
storeA.push(_root[obj]);
}
}
}
};
Mouse.addListener(someListener);
R_Anthony
5/11/2004 3:48:53 PM
kglad
5/12/2004 12:51:59 AM
R_Anthony
5/17/2004 6:02:47 PM
Thanks for you help thus far, however I'm not sure that the code you provided
will do what I'm trying to get done. Let me try to explain again what I'm
trying to do. I have a image inside a movie clip on the main timeline. I want
to select the movieclip and then using a submit button store the movieClip ID
in an array so it can be retrieved latter in the movie. This seems like such a
basic activity but I can't find any examples of it any where. I closest thing
I've found is a shopping cart type of operation but it stores only text.
Thanks again

mandingo
5/17/2004 11:48:36 PM
What kglad has provided is accurate and should meet your needs.

The code in layman's terms checks your movieClip and finds which image you
clicked on using the position of your mouse, then stores that image name in an
array. That was what you asked to do.

obj is just a variable being used by kglad to make the code simple to read...
it isn't anything specific to Flash code.

To find the instance of the movieClip that you clicked on in kglad's code, you
would reference :
storeA[0]
if you had clicked on several images, then the last image would be
storeA[storeA.length-1]; (an array being zero indexed)

hope that sheds some light on it
cheers,
AddThis Social Bookmark Button