Wednesday, August 25, 2010
this is a test that I did to study addChild in flash hover over create to make the images, touch the images to delete them
hover over delete to remove all of them
heres the code
var ball1:Ball = new Ball;
var ball2:Ball = new Ball;
var ball3:Ball = new Ball;
var ball4:Ball = new Ball;
var ball5:Ball = new Ball;
var ball6:Ball = new Ball;
var ball7:Ball = new Ball;
var ball8:Ball = new Ball;
var timer:Number = 0
var theempty:Number = 8
var deleteball:Array = new Array();
addEventListener(Event.ENTER_FRAME, update)
function update(event:Event)
{
//when you hit the restart addChild
if(bill.hitTestObject(therestart) && theempty == 8)
{
ball1.x = 0
ball2.x = 50
ball3.x = 100
ball4.x = 150
ball5.x = 200
ball6.x = 250
ball7.x = 300
ball8.x = 350
addChild(ball1)
addChild(ball2)
addChild(ball3)
addChild(ball4)
addChild(ball5)
addChild(ball6)
addChild(ball7)
addChild(ball8)
deleteball.push(ball1,ball2,ball3,ball4,ball5,ball6,ball7,ball8)
theempty = 0
}
bill.x = mouseX;
bill.y = mouseY;
for(var b:int = 0; b < deleteball.length; b++)
{
if(bill.hitTestObject(deleteball[b]))
{
if(bill.y < deleteball[b].y)
{
deleteball[b].y+=9
}
if(bill.y > deleteball[b].y)
{
deleteball[b].y-=9
}
}
deleteball[b].x++
}
timer++
if(timer >= 1)
{
trace(theempty)
for(var i:int = 0; i < deleteball.length; i++)
{
if(bill.hitTestObject(deleteball[i]))
{
if(deleteball[i] == ball5) //this has to go before you delete
{
trace("HIT IT")
}
removeChild(deleteball[i])
deleteball.splice(i,1)
i--
theempty++
}
if(bill.hitTestObject(bar))
{
removeChild(deleteball[i])
deleteball.splice(i,1)
i--
theempty++
}
//removeChild(deleteball[i])
}
}
if(theempty == 8)
{
trace("empty")
}
if(bill.hitTestObject(ball5))
{
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment