|
-
Hittesting an array
I have a movieclip which is created every time the left key is pressed, and I was wondering how I would go about hittesting all of them.
Code:
Creating movieclip:
if(Key.isDown(Key.SPACE)){
for(k=0;k<=100;k++){
lb[k] = attachMovie("left","left"+k,depth++)
}
}
Attempt at hittesting:
for(n=0;n<=100;n++){
if (slider.hitTest("left"+[n])){
trace("left")
}
}
-
I've changed it to this and I'm only getting left0 (lb0)to work..
Actionscript Code:
for(k=0;k<=100;k++){ lb[k].onEnterFrame=function(){ if(this.hitTest(_root.slider)){ trace("left") } }
-
Maybe you can adapt this...
Code:
var k = 0;
var lb = new Array();
this.onEnterFrame = function() {
var len = lb.length;
if (Key.isDown(Key.SPACE)) {
if (len<100) {
len = lb.push(attachMovie("left", "left"+k, k++, {_x:3*k, _y:3*k}));
}
}
for (var j = len; j>=0; --j) {
if (lb[j].hitTest(_root.slider)) {
trace(lb[j]._name);
lb[j].removeMovieClip();
lb.splice(j,1);
}
}
};
-
Cool, now I have adapted that code in, and the hittest works, but the movieclips aren't showing up. I've tried to change the depth variable, but I'm still without luck. Anyone know what's the problem?
-
Post the code that you are now using...
-
Actionscript Code:
Attaching: var len = lb.length; if (len<100) { len = lb.push(attachMovie("left", "left"+k, depth++, {_x:3*k, _y:3*k})); } Placement: for(j=0;j<=100;++j){ lb[j]._x = lxstart lb[j]._y = 27 } Hittest: for(j=lb.length;j>=0;--j){ if(lb[j].hitTest(_root.slider)){ trace("hit") } }
lxstart = slider._x
-
Code:
//Attaching:
var len = lb.length;
// k needs to be initialized before use
var k=0;
// also make sure depth is initialized prior to use
if (len<100) {
len = lb.push(attachMovie("left", "left"+k++, depth++, {_x:3*k, _y:3*k}));
}
//Placement:
for (j=0; j<=100; ++j) {
lb[j]._x = lxstart;
lb[j]._y = 27;
}
//Hittest:
for (j=lb.length; j>=0; --j) {
if (lb[j].hitTest(_root.slider)) {
trace("hit");
}
}
-
i already have both those variables initialized in onLoad=function(){
Last edited by sora72; 02-13-2010 at 03:51 AM.
-
I'm still unable to find out the problem as to why each movieclip "deletes" the one before it. Does anyone have a clue whats wrong?
-
Code:
var len = lb.length;
var k=0;
if (len<100) {
k++
len = lb.push(attachMovie("left", "left"+k, this.getNextHighestDepth(), {_x:3*k, _y:3*k}));
}
//Placement:
for (j=0; j<=100; j++) {
lb[j]._x = lxstart;
lb[j]._y = 27;
}
//Hittest:
for (j=lb.length; j>=0; j--) {
if (lb[j].hitTest(_root.slider)) {
trace("hit");
}
}
try this.... not sure how you have this set out so if it doesnt work, try changing the this.getNextHighestDepth() to _root.getNextHighestDepth()
Freelance: AS2, AS3, PHP, MySQL, JavaScript
Skype: hunty93
-
the depth isn't the problem. it has something to do with the placement. it's causing all the attached movies to move to the latest placement.
-
can you post the .fla? ,.. just makes it easier to find the problem.
Freelance: AS2, AS3, PHP, MySQL, JavaScript
Skype: hunty93
-
sorry... it's been fixed.
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
|