Hi
this is what i am trying to achieve , i have a bike and two boxes on stage , i want the boxes to disappear when the bike touches the boxes, i can achieve this while doing coding from frame by simply doing this
////////////
box1.hitTestObject(bike);
////////////////////
but when i try and do the same from class its not working , here is code from my main class
////////////////////
package
{
import wck.WCK;
import flash.display.*;
import flash.events.*;
public class Main extends WCK
{
var hit1:MyRectabgle=new MyRectabgle();
var hit2:MyRectabgle=new MyRectabgle();
var hero:Vehicle=new Vehicle();
var myArray=new Array(hit1,hit2);
public function Main()
{
hero.addEventListener(Event.ENTER_FRAME, EnterFrame1);
// hero.addEventListener(Event.ENTER_FRAME, Collision);
}
/////////////////////////
function EnterFrame1(event:Event):void {
for (var i:Number = 0; i < myArray.length; i++){
if (hero.hitTestObject(myArray[i])){
//trace("done");
removeChild(myArray[i]);
}
/////////////////////
}
}
}
}
//////////////////////
Its giving error at removechild , also i am trying call boxes here by giving them instance name hit1 and hit2, any help will be appreciated ....
Regards
Jin
this is what i am trying to achieve , i have a bike and two boxes on stage , i want the boxes to disappear when the bike touches the boxes, i can achieve this while doing coding from frame by simply doing this
////////////
box1.hitTestObject(bike);
////////////////////
but when i try and do the same from class its not working , here is code from my main class
////////////////////
package
{
import wck.WCK;
import flash.display.*;
import flash.events.*;
public class Main extends WCK
{
var hit1:MyRectabgle=new MyRectabgle();
var hit2:MyRectabgle=new MyRectabgle();
var hero:Vehicle=new Vehicle();
var myArray=new Array(hit1,hit2);
public function Main()
{
hero.addEventListener(Event.ENTER_FRAME, EnterFrame1);
// hero.addEventListener(Event.ENTER_FRAME, Collision);
}
/////////////////////////
function EnterFrame1(event:Event):void {
for (var i:Number = 0; i < myArray.length; i++){
if (hero.hitTestObject(myArray[i])){
//trace("done");
removeChild(myArray[i]);
}
/////////////////////
}
}
}
}
//////////////////////
Its giving error at removechild , also i am trying call boxes here by giving them instance name hit1 and hit2, any help will be appreciated ....
Regards
Jin

