PDA

View Full Version : mutiple hit Test2(array must b some1 who can)


hansolo
03-02-2008, 12:50 PM
var tasks:Array = ["target1", "target2"];



var i:Number;
for (i = 1; i <= 3; i++) {
if (ball_mc.hitTest(target1)) {

_root.["target" + i]._visible = false;


}

want to make a mutiple hitTest for sprites on the stage area, i dont know how to do this trying to access the array but no luck ...im new to arrays so
any help cheers the code above and syntax is wrong

inhan
03-02-2008, 02:30 PM
for (var i:Number = 1; i <= 3; i++) {
var mc:MovieClip = _root["target"+i];
if (ball_mc.hitTest(mc)) {
mc._visible = false;
}
}But unless you're calling this as a function repeatedly it will check only at the frame it is written, and only once.

hansolo
03-04-2008, 12:18 PM
var tasks:Array = ["target1", "target2"];


for (var i:Number = 1; i <= 3; i++) {
var mc:MovieClip = _root["target"+i];
if (ball_mc.hitTest(mc)) {
trace(hit)
mc._visible = false;
}
}

thanks for you help do i still have to create an array with names and if so .......var mc:MovieClip = _root["target"+i];....
on the hit test of mc does the movie clip mc have to be name inside the array

inhan
03-04-2008, 03:05 PM
If the names are sequential then you don't need to use an array; iteration of a variable would do just fine. An example to a repeating code is:

ball_mc.onEnterFrame = function() {
for (var i:Number = 1; i <= 3; i++) {
var mc:MovieClip = _root["target"+i];
if (this.hitTest(mc)) {
trace("ball has hit " + mc);
mc._visible = false;
}
}
};

hansolo
03-05-2008, 05:46 PM
the variable name
var mc
how does that refer to rhe movieclips on the stage... is one of the movieclips on the stage have to be named Mc

var:Mc,Mc1,Mc2;
to make mutliple the hitTest

inhan
03-05-2008, 08:02 PM
No, 'mc' there is a temporary variable that only holds all the movie clips referred in the loop. The names of your mc's are the value assigned to this variable, that is, target1, target2 and target3.

hansolo
03-07-2008, 05:05 PM
var mc:Object = target1,target2;

ball_mc.onEnterFrame = function() {
for (var i:Number = 1; i <= 3; i++) {
var mc:MovieClip = _root["target"+i];
if (this.hitTest(mc)) {
trace("ball has hit " + mc);
mc._visible = false;
}
}
};


so would the above variable work var mc:Object = target1,target2; written as above
and the movieclips on stage called target1 target2

is that correct im still unsure

inhan
03-08-2008, 12:17 AM
Except the first line. You can not create an object this way.
But other than that this script should work. Just delete the first line.

hansolo
03-13-2008, 10:02 PM
im sorry im new to actionscript and the code is well above what i understand at the moment, but can i do this with an array .. code below how can access i make the array the instants names on the stage so when hit the target....there would be a possible trace ...

var target:Array = ["Arun", "Peter"];
for(var i:Number = 0; i < target.length; i++){
trace( target[i]);
}

box_mc.onEnterFrame = function(){
if (this.hitTest[target]){
trace("hit")


}
}

function moveSpeed(){
box_mc._x = _xmouse
box_mc._y = _ymouse
}

inhan
03-14-2008, 12:10 AM
var targets:Array = [Arun, Peter];
// don't use quotes if 'Arun' and 'Peter' are names of movie clips on the stage
// I also changed the array name because this might cause unexpected results
// considering 'target' is one of the reserved words in AS.
box_mc.onEnterFrame = function() {
for (var i:Number = 0; i < targets.length; i++) {
if (this.hitTest(targets[i])) {
// mc.hitTest(another_mc) is the right use of this method
// so don't forget to use parantesis to wrap the affected mc name
trace("box hit " + targets[i]);
}
}
}

hansolo
03-24-2008, 06:09 PM
cheers ali thats worked thanks alot mate

for (var i:Number = 0; i < targets.length; i++) {
if (this.hitTest(targets[i]))

just 1 question is that the generic way of writing
if (this.hitTest(targets[i]))

to access the array thanks alot

inhan
03-25-2008, 12:21 PM
The array part is 'targets[i]' only, remaining is the standard hitTest method.