function checkHits(obj) {
var hitArr=new Array();
for(i in _root) {
if(_root[i].hitTest(obj) && _root[i]!=obj) {
hitArr.push(String(_root[i]));
}
for(j in _root[i]) {
if(_root[i][j].hitTest(obj) && _root[i][j]!=obj) {
hitArr.push(String(_root[i][j]));
}
}
}
}
It returns the absoloute address of everything touching object obj either in root or in an MC in root. im not sure how to do it so it does it with infinate stages of nesting though.
for .... in .... basically goes through each object in another object.
for..in Availability
Flash Player 5.
Usage
for(variableIterant in object){ statement(s);
}
Parameters variableIterant The name of a variable to act as the iterant, referencing each property of an object or element in an array.
object The name of an object to be repeated.
statement(s) An instruction to execute for each iteration.
Returns
Nothing.
Description
Statement; loops through the properties of an object or element in an array, and executes the statement for each property of an object.
Some properties cannot be enumerated by the for or for..in actions. For example, the built-in methods of the Array class (such as Array.sort() and Array.reverse()) are not included in the enumeration of an Array object, and movie clip properties, such as _x and _y, are not enumerated. In external class files, instance members are not enumerable; only dynamic and static members are enumerable.
The for..in statement iterates over properties of objects in the iterated object's prototype chain. If the child's prototype is parent, iterating over the properties of the child with for..in, will also iterate over the properties of parent.
The for..in action enumerates all objects in the prototype chain of an object. Properties of the object are enumerated first, then properties of its immediate prototype, then properties of the prototype's prototype, and so on. The for..in action does not enumerate the same property name twice. If the object child has prototype parent and both contain the property prop, the for..in action called on child enumerates prop from child but ignores the one in parent.
Example
The following is an example of using for..in to iterate over the properties of an object:
myObject = { name:'Tara', age:27, city:'San Francisco' };
for (name in myObject) {
trace ("myObject." + name + " = " + myObject[name]);
}
The output of this example is as follows:
myObject.name = Tara
myObject.age = 27
myObject.city = San Francisco
The following is an example of using the typeof operator with for..in to iterate over a particular type of child:
for (name in my_mc) {
if (typeof (my_mc[name]) = "movieclip") {
trace ("I have a movie clip child named " + name);
}
}
The following example enumerates the children of a movie clip and sends each to Frame 2 in their respective Timelines. The RadioButtonGroup movie clip is a parent with several children, _RedRadioButton_, _GreenRadioButton_ and _BlueRadioButton.
for (var name in RadioButtonGroup) {
RadioButtonGroup[name].gotoAndStop(2);
}
Also, in the function i wrote, i forgot to include the line:
return hitArr;
So add that to the end of it.
But what do you want it to do every frame. This function just returns the addresses of MCs. It doesn't actually do anything with them.
in the included .fla, press new and launch a new 'striker' and a new 'sound'.
it is set up to trace all mc address that hit the sound, so if you move it about, you'll see the effect in the output window.
you can see the names for _level0.striker1.sp1 , sp2, sp3 and sp4
this doesnt work properly, as it should output those values whenever the sound is above a spoke of the striker wheel
also, because the strikers are dynamically labeled (striker1, striker2, striker3, etc)
i need it to identify when it has been struck by an embedded spoke (sp1, sp2 etc) and then return its full address, so that i can retreive a variable embedded within that specific spoke object (click and release on the striker to bring up the settings page, you'll see what i mean)
this is for a uni project, and implementing this has been a royal pain!!
i dont know if this would help, but all strikers address's are kept in a global array, _root.strikers. could i use that to help identify which striker is being used, and then which spoke within that?
Wow, this is a very cool idea. Can you send me the final version when its done cos i'd quite like to see how it turns out .
I've done the code as if the sound things were rectangular. I know its not perfect but due to the number of nested MCs with different rotations it would be really hard to get a good hittest and im just too tired at the moment. If you need it to hittest the circles and not just the circles bounding boxes then hassle me some more.
What i've done is put 10 points on each spoke and it hittests the sound object against each point in each spoke in each striker. Man those nested for statements are confusing. I used i, j and k!
But yeah, heres the source. This returns the address of each spoke touching the sound object.
Tell me if you need some more help, or if you want me to run through the code or whatever.
And good luck with it
btw - you should probably make a statement on the first frame of the hitTestPoint MC that says _visible=false.
thats wicked! one step closer to actually working!!
could you talk me through the workings of the above code? the thing i find difficult at the moment is i need to use the results to control the output of a sound. when the sound gets struck by 2 spokes at the same time, it outputs an array list, which i am not sure how to break down.
to avoid retriggering of sounds, i need it to only output once each hit. i have an idea of how to do this, but i dont fully grasp your code
also, do you think it might be best to have each spoke assess the impact of a sound, rather than the way round we have it now?
cheers for your help, and the finished product will be online when finished, again, as part of the project!