Copy link to clipboard
Copied
I know I already asked a few months ago but I wasn't specific enough and had less coding expirience. I don't know how to code in a class so I want to code in a keyframe if that makes sense.
I want to have a thing that can collide with a bunch of squares that I added to stage through code. The only way I know how to do this is by painstakingly dragging each instance to the stage and giving it another name and using multiple hitTestObject but I don't want to do that.
This would be very helpful for things like a catcher game, flappy bird, snake game, etc. What is the best way to do this?
you only use the hittest when creating a square. you probably want to start a loop (eg, enterframe) when dragging and perform hittests.
Copy link to clipboard
Copied
one way; add the elements to an array and loop through the array using your hittestobject. eg,
var a:Array = [];
var sqNum:int = 22;
for(var i:int=0;i<sqNum;i++){
createSquareF();
}
function createSquareF():void{
var sq:MovieClip = new Square(); // linkage id
// add to stage, position etc
a.push(sq);
}
function hitTestF():void{
for(var i:int=a.length-1;i>=0;i--){
if(yourthing.hitTestObject(a[i])){
// do whatever. loop backwards if you are "destroying" a elements and want to remove them from the array.
}
}
}
Copy link to clipboard
Copied
ok, i adjusted it and there is no errors except one saying the paramater must be non-null or a weirder one where i said the popping value to 1 and "Property 1 not found on builtin.as$0.MethodClosure and there is no default value." however it's not doing anything at all. here's the code
Copy link to clipboard
Copied
actually ignore the pop because i actually just made thesquare move somewhere else rather than deleting it. there's no errors
Copy link to clipboard
Copied
your for-loop's initial value is incorrect.
Copy link to clipboard
Copied
what do you mean?
Copy link to clipboard
Copied
for(var i:int=aaa.length; i>=0;i--)
should be
for(var i:int=aaa.length-1; i>=0;i--)
Copy link to clipboard
Copied
still does nothing 😞
Copy link to clipboard
Copied
do you see any error message(s) when testing?
Copy link to clipboard
Copied
nuh uh
Copy link to clipboard
Copied
upload your file to a online storage and post here the link
Copy link to clipboard
Copied
hold i just have to figure out how to do that
Copy link to clipboard
Copied
i just have ot clear some storage
Copy link to clipboard
Copied
google it. eg, wetransfer, onedrive, etc
Copy link to clipboard
Copied
Copy link to clipboard
Copied
oh wait nvm
Copy link to clipboard
Copied
?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
your fla file
Copy link to clipboard
Copied
oh right that doesn't work
Copy link to clipboard
Copied
i emailed it to you (hopefully)
Copy link to clipboard
Copied
hold on
Copy link to clipboard
Copied
Copy link to clipboard
Copied
tha tshould work
Copy link to clipboard
Copied
you only use the hittest when creating a square. you probably want to start a loop (eg, enterframe) when dragging and perform hittests.