Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-03-2008, 02:41 PM   #1
lupien
Ti-guy
 
Join Date: Mar 2008
Posts: 5
Default Trace _name of the instance hitTest detected a collision

Hi,

I`m builing a game that as a canon that shots balls to try to break walls. I have gravity on that ball and when it hits solid blocks (walls, floors) its bounces. All the block are position in the level with attachMovie. So the breakable blocks are attached inside a movieClip and the unbreakable solid blocks are in a movieClip called "terrain".

The hitTest is setup on the ball i`m shooting.
ActionScript Code:
if (_root.terrain.hitTest((spot_x+_root.cannon._x), (spot_y+_root.cannon._y), true)) {  //Bounce the ball function is called }

spot_x and spot_y are specific coordinates on the circumference of the ball. So this part work just fine.

Now here is my question and I don`t know if its even possible.
Each block within "terrain" movieClip has its own instance name. I need to find out which block the ball hit. The hitTest his checking if "terrain" is hit so how can I check what movieClip within "terrain" was it?? I`m trying to trace the instance name of the individual blocks but I just can`t figure it out.

Thanks.
lupien is offline   Reply With Quote
Old 03-03-2008, 03:01 PM   #2
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

ActionScript Code:
for(i=0;i<numberofblocks;i++){ if (_root["terrain"+i].hitTest((spot_x+_root.cannon._x), (spot_y+_root.cannon._y), true)) {  //Bounce the ball function is called trace(_root["terrain"+i]._name); } }

this would work with block instances name like terrain0, terrain1, ect...
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Old 03-03-2008, 03:11 PM   #3
lupien
Ti-guy
 
Join Date: Mar 2008
Posts: 5
Default

Actually i`m trying to trace movieClip name inside of terrain.
Example: Instance name = box1 which is _root.terrain.box1
lupien is offline   Reply With Quote
Old 03-03-2008, 03:27 PM   #4
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

you did not provide the instance name for the inside blocks so let's say it's insideblock1, insideblock2, ....ect

for(i=0;i<numberofblocks;i++){
if (_root.terrain["insideblock"+i].hitTest((spot_x+_root.cannon._x), (spot_y+_root.cannon._y), true)) {
//Bounce the ball function is called
trace(_root.terrain["insideblock"+i]._name);
}

}
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Old 03-03-2008, 03:37 PM   #5
lupien
Ti-guy
 
Join Date: Mar 2008
Posts: 5
Default

Thanks man.

I was just about to write the exact same thing explaining how I figured it out. That works perfect.
lupien is offline   Reply With Quote
Old 03-03-2008, 03:52 PM   #6
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

Cool!
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Instance Properties to AS2 Class ncat007 ActionScript 2.0 3 06-19-2006 09:28 PM
Trace instance of attached MovieClip silencer01 ActionScript 1.0 (and below) 1 01-06-2006 10:04 AM
[AS2] trouble with hitTest tarragon Gaming and Game Development 4 06-14-2005 10:13 AM
Database simulated with arrays on a cd-rom lecasn5 Components 61 09-07-2004 11:40 AM
inheritance - Mortimer Jazz ActionScript 1.0 (and below) 10 07-24-2003 09:51 PM


All times are GMT. The time now is 06:10 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.