• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

AS3: How do I do collision with multiple instances?

Participant ,
May 19, 2023 May 19, 2023

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?

TOPICS
ActionScript , Code , How to , Other

Views

707

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 20, 2023 May 20, 2023

you only use the hittest when creating a square.  you probably want to start a loop (eg, enterframe) when dragging and perform hittests.

Votes

Translate

Translate
Community Expert ,
May 19, 2023 May 19, 2023

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.

}

}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 19, 2023 May 19, 2023

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

 

var aaa:Array = [];
var sqNum:int = 10;
 
for(var i:int=0;i<sqNum;i++)
{
createSquareF();
}
 
 
function createSquareF():void
{
var squarey:square = new square(); 
addChild(squarey)
squarey.x = (Math.random()* 669)
squarey.y = (Math.random()* 420)
aaa.push(squarey);
if (thing.hitTestObject(aaa[i]))
{
removeChild(squarey)
aaa.pop[1]
}
}
 
 
 
function hitTestF():void
{
for(var i:int=aaa.length; i>=0;i--)
{
if(thing.hitTestObject(aaa[i]))
{
trace("ad")
}
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 19, 2023 May 19, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2023 May 19, 2023

Copy link to clipboard

Copied

your for-loop's initial value is incorrect.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 19, 2023 May 19, 2023

Copy link to clipboard

Copied

what do you mean?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2023 May 19, 2023

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--)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

still does nothing 😞

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

do you see any error message(s) when testing?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

nuh uh

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

upload your file to a online storage and post here the link 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

hold i just have to figure out how to do that

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

i just have ot clear some storage

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

google it. eg, wetransfer, onedrive, etc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

could i just email it to you

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

oh wait nvm

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

your fla file

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

oh right that doesn't work

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

i emailed it to you (hopefully)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

hold on

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

tha tshould work

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2023 May 20, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines