Chess board interface. Cannot remove child. Any suggestions? - actionscript-3

Hello
I am in the process of creating a chess board where you can move the pieces. Currently i am working on the rook and the coding is below. I know it is not elegant and probably the most inefficient code out there, but this is day 2 of my actionscript 3.0 life and i am kinda a beginner. Anyway, so the thing is, when you click the piece the code below figures out the possible ways to go. Then green squares appear at those places. You can then press those green squares and then the rook will move there.
Ok, now to the problem. The squares will not go away. I want them all to be deleted when i have clicked on one of them and the rook will move there.
I have tried removeChild(), but since that happens in a different function it does not work. So if you are so kind to look through the code and suggest a solution, your help is much appreciated.
Kind Regards Emile
https://picasaweb.google.com/109156245246626370734/Jun42011?authkey=Gv1sRgCMy4v_b01aikzAE&feat=directlink
import flash.display.Sprite
import flash.events.MouseEvent
import flash.text.TextField;
import flash.geom.Point;
import caurina.transitions.*
myPoint.addEventListener(MouseEvent.MOUSE_DOWN, startMove);
function startMove(evt:MouseEvent) {
var boxNum:int = Math.floor(myPoint.y/100)+1;
for (var i:int = 1; i <boxNum; i++) {
var box:Ball = new Ball();
box.x = myPoint.x;
box.y = myPoint.y - i * box.height;
addChild(box);
Tweener.addTween(box, {alpha:0.5});
box.buttonMode = true;
box.addEventListener(MouseEvent.ROLL_OVER, onOver,
false, 0, true);
box.addEventListener(MouseEvent.ROLL_OUT, onOut,
false, 0, true);
box.addEventListener(MouseEvent.MOUSE_DOWN, onclick);
}
var boxNum1:int = Math.floor((800-myPoint.y)/100)+1;
for (var i:int = 1; i <boxNum1; i++) {
var box1:Ball = new Ball();
box1.x = myPoint.x;
box1.y = myPoint.y + i * box.height;
addChild(box1);
Tweener.addTween(box1, {alpha:0.5});
box1.buttonMode = true;
box1.addEventListener(MouseEvent.ROLL_OVER, onOver,
false, 0, true);
box1.addEventListener(MouseEvent.ROLL_OUT, onOut,
false, 0, true);
box1.addEventListener(MouseEvent.CLICK, onclick);
}
var boxNum2:int = Math.floor(myPoint.x/100)+1;
for (var i:int = 1; i <boxNum2; i++) {
var box2:Ball = new Ball();
box2.x = myPoint.x - i * box.height;
box2.y = myPoint.y;
addChild(box2);
Tweener.addTween(box2, {alpha:0.5});
box2.buttonMode = true;
box2.addEventListener(MouseEvent.ROLL_OVER, onOver,
false, 0, true);
box2.addEventListener(MouseEvent.ROLL_OUT, onOut,
false, 0, true);
box2.addEventListener(MouseEvent.CLICK, onclick);
}
var boxNum3:int = Math.floor((800-myPoint.x)/100)+1;
for (var i:int = 1; i <boxNum3; i++) {
var box3:Ball = new Ball();
box3.x = myPoint.x + i * box.height;
box3.y = myPoint.y;
addChild(box3);
Tweener.addTween(box3, {alpha:0.5});
box3.buttonMode = true;
box3.addEventListener(MouseEvent.ROLL_OVER, onOver, false, 0, true);
box3.addEventListener(MouseEvent.ROLL_OUT, onOut, false, 0, true);
box3.addEventListener(MouseEvent.CLICK, onclick);
}
}
function onOver(evt:Event):void {
var box:MovieClip = MovieClip(evt.target);
addChild(box)
box.scaleX = box.scaleY = 1.1;
}
function onOut(evt:Event):void {
evt.target.scaleX = evt.target.scaleY = 1;
}
function onclick(Event:MouseEvent):void {
var xcod:int = Math.ceil(mouseX/100)*100-50;
var ycod:int = Math.ceil(mouseY/100)*100-50;
Tweener.addTween(myPoint, {x:xcod, y:ycod, time:1, transition:"linear"});
}

alxx's answer is correct, you wouldn't need to keep a special list for them. The other way you could do it, using an Array to save references, would look like this:
var boxes:Array = new Array();
function startMove(evt:MouseEvent):void {
...
var box:Ball = new Ball();
addChild(box);
boxes.push(box);
...
var box1:Ball = new Ball();
addChild(box1);
boxes.push(box1);
...
}
function onClick(evt:MouseEvent):void {
for each (var box:Ball in boxes) {
removeChild(box);
}
boxes = new Array();
}

You can put temporary highlights in separate Sprite. Then your board will looks as follows:
Stage children: base board, highlights, pieces, in that order.
When you need to remove highlights, you can iterate highlights' children with numChildren and getChildAt and call removeChild on each, you don't even need a special list for them.

Related

AS3 addChild with multiple buttons top layer fails

this seems like an odd one as it seems pretty straight forward, I have a movieclip that contains a back and forward button to invoke a tween for 2 groups of buttons to slide accross the screenI addChild then make the tween and then removeChild for the old group of buttons to leave the new one on the screen.
My question is when the second group comes in with all the buttons the button that is on the top layer of the movieclip fails to work (rollOver Tween and all) if I change which button is on the top layer then that one fails.
any ideas as to why this may occur so I can make a fix?
code for process is below.
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.Strong;
import flash.events.*;
import flash.display.MovieClip;
fOverlay.addEventListener(MouseEvent.ROLL_OVER, mOver);
fOverlay.addEventListener(MouseEvent.ROLL_OUT, mOut);
fOverlay.addEventListener(MouseEvent.CLICK, mDown);
bOverlay.addEventListener(MouseEvent.ROLL_OVER, mOverB);
bOverlay.addEventListener(MouseEvent.ROLL_OUT, mOutB);
bOverlay.addEventListener(MouseEvent.CLICK, mDownB);
var butts1:MovieClip = new sButtons1;
var butts2:MovieClip = new sButtons2;
addChild(butts1);
butts1.x = -10;
butts1.y = 0;
function mOver(e:MouseEvent)
{
var mouseOTween:Tween = new Tween(fBack, "alpha", Strong.easeOut,0.2,0.8,1,true);
}
function mOut(e:MouseEvent)
{
var mouseOTween:Tween = new Tween(fBack, "alpha", Strong.easeOut,0.8,0.2,1,true);
}
function mOverB(e:MouseEvent)
{
var mouseOTween:Tween = new Tween(bBack, "alpha", Strong.easeOut,0.2,0.8,1,true);
}
function mOutB(e:MouseEvent)
{
var mouseOTween:Tween = new Tween(bBack, "alpha", Strong.easeOut,0.8,0.2,1,true);
}
function mDown(e:MouseEvent)
{
if (butts1.stage)
{
addChild(butts2)
butts2.x = 1832;
butts2.y = 0;
var nTweenout1:Tween = new Tween(butts1,"x", Strong.easeInOut, -10, -1860, 1, true);
var nTweenin1:Tween = new Tween(butts2,"x", Strong.easeInOut, 1832, -10, 1, true);
nTweenout1.addEventListener(TweenEvent.MOTION_FINISH, moFinish1);
function moFinish1(e:TweenEvent)
{
removeChild(butts1);
}
}
else if (butts2.stage)
{
addChild(butts1)
butts1.x = 1832;
butts1.y = 0;
var nTweenout2:Tween = new Tween(butts2,"x", Strong.easeInOut, -10, -1860, 1, true);
var nTweenin2:Tween = new Tween(butts1,"x", Strong.easeInOut, 1832, -10, 1, true);
nTweenout2.addEventListener(TweenEvent.MOTION_FINISH, moFinish2);
function moFinish2(e:TweenEvent)
{
removeChild(butts2);
}
}
else
{
MovieClip(root).addChild(butts1)
butts1.x = -10;
butts1.y = 0;
}
}
function mDownB(e:MouseEvent)
{
if (butts1.stage)
{
addChild(butts2)
butts2.x = -1860;
butts2.y = 0;
var nTweenoutB1:Tween = new Tween(butts2,"x", Strong.easeInOut, -1860, -10, 1, true);
var nTweeninB1:Tween = new Tween(butts1,"x", Strong.easeInOut, -10, 1832, 1, true);
nTweenoutB1.addEventListener(TweenEvent.MOTION_FINISH, moFinish3);
function moFinish3(e:TweenEvent)
{
removeChild(butts1);
}
}
else if (butts2.stage)
{
addChild(butts1)
butts1.x = -1860;
butts1.y = 0;
var nTweenoutB2:Tween = new Tween(butts1,"x", Strong.easeInOut, -1860, -10, 1, true);
var nTweeninB2:Tween = new Tween(butts2,"x", Strong.easeInOut, -10, 1832, 1, true);
nTweenoutB2.addEventListener(TweenEvent.MOTION_FINISH, moFinish4);
function moFinish4(e:TweenEvent)
{
removeChild(butts2);
}
}
else
{
addChild(butts1)
butts1.x = -10;
butts1.y = 0;
}
}
I suspect you've got objects overlapping eachother. In that case, only the top-most object will receive the mouse event. If so, it is expected behavior. An example of this can be seen with a transparent png.
Without the rest of your DisplayList structure or appearance of your UI, I can't say exactly what's plaguing your events. However, I think the code below might help clear up some things.
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.Strong;
import flash.events.*;
import flash.display.MovieClip;
var butts1:MovieClip = new sButtons1;
var butts2:MovieClip = new sButtons2;
var lookup:Dictionary = new Dictionary(true);
var removeTarget:MovieClip = null; // This is the next object to be removed from onscreen
var onComplete:Tween = null; // A reference to the tween the calls our remove
function init():void {
// It's healthy to keep your initialization routine grouped away from the rest of your program logic.
// Optionally, you can recall the function to rerun first time setup, if necessary.
addChild(butts1);
butts1.x = -10;
butts1.y = 0;
// Use event target as a key in our dictionary to correspond which objects should be hidden/shown
// This way, we can keep our code consistent and maintainable from one function.
lookup[fOverlay] = {
"back":fBack,
"out":butts1,
"in":butts2
}
lookup[bOverlay] = {
"back":bBack,
"out":butts2,
"in":butts1
}
// Because we're registering the same events to the same functions, we can handle it through a loop.
var overlayEvents:Array = ["rollOver", "rollOut", "click"];
for (var overlay in lookup) {
for each (var type:String in overlayEvents) {
overlay.addEventListener(type, overlayListener, false, 0, true);
}
}
}
function overlayListener(e:MouseEvent):void {
// Having generalized our objects, we swap for the appropriate object based on the type of event.
switch (e.type) {
case "rollOver":
new Tween(lookup[e.currentTarget].back, "alpha", Strong.easeOut,0.2,0.8,1,true);
break;
case "rollOut":
new Tween(lookup[e.currentTarget].back, "alpha", Strong.easeOut,0.8,0.2,1,true);
break;
case "click":
var show:MovieClip, hide:MovieClip;
if (lookup[e.currentTarget].out.stage) {
hide = lookup[e.currentTarget].out;
show = lookup[e.currentTarget].in;
} else if (lookup[e.currentTarget].in.stage) {
hide = lookup[e.currentTarget].in;
show = lookup[e.currentTarget].out;
} else {
show = butts1;
addChild(show);
}
show.x = 1832;
show.y = 0;
new Tween(hide, "x", Strong.easeInOut, -10, -1860, 1, true);
if (hide != null) {
removeTarget = hide;
if (onComplete != null) {
onComplete.stop()
onComplete.rewind()
}
onComplete = new Tween(show, "x", Strong.easeInOut, 1832, -10, 1, true);
onComplete.addEventListener("motionFinish", remove, false, 0, true);
}
break;
}
}
function remove(e:Event):void {
if (removeTarget != null) {
removeChild(removeTarget)
removeTarget = null;
onComplete.removeEventListener("motionFinish", remove);
onComplete = null;
}
}
init();

Struggling with Actionscript computeSpectrum and beat detection

I am trying to understand the values given back to me from the computeSpectrum method. I want to work with the lower frequencies pick out the bass drum of a track. The numbers I am getting back from the byteArray make no sense. For example, it says that the value is 0 when there is clearly a sound playing. What am I missing here...I do know beat detection is not easy and have looked at most of the posts here on the subject...It's just that the numbers that are returned to me make no sense, can somebody explain them to me? Thanks in advance.
My Code:
import flash.display.Graphics;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.net.URLRequest;
import flash.display.MovieClip;
var snd: Sound = new Sound();
var req: URLRequest = new URLRequest("mySong.mp3");
snd.load(req);
var channel: SoundChannel;
channel = snd.play();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
snd.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
const CHANNEL_LENGTH: int = 256;
const BUFFER_LENGTH: int = 512;
var bytes:ByteArray = new ByteArray();
function onEnterFrame(event: Event): void
{
SoundMixer.computeSpectrum(bytes, true, 0);
for (var i:int = 0; i < CHANNEL_LENGTH; i++) // channel_length = 256
{
var sampleValue:Number = bytes.readFloat() * 200;
var byteArrayIndex = bytes.position;
trace(byteArrayIndex, sampleValue);
}
}
function onPlaybackComplete(e:Event):void
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
Nice to meet you again, I think I'm more understand your mind this time.
If you are going to check whether there exist a 'beat' at a specific time of the song;
I may suggest this method for reference:
import flash.events.Event;
var snd: Sound = new Sound();
var req: URLRequest = new URLRequest("mySong.mp3");
snd.load(req);
var channel: SoundChannel;
channel = snd.play();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
snd.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
// I want to specify which region of byteData is passing to my check function.
// this two value help me to extract the sample I need.
var checkLength:int = 20;
var checkStart:int = 0;
var theshold:Number = 0.5; // How big the value should I determine it is the 'beat'.
const CHANNEL_LENGTH: int = 256;
const BUFFER_LENGTH: int = 512;
var myArray:Array;
var bytes:ByteArray = new ByteArray();
function onEnterFrame(event: Event): void
{
SoundMixer.computeSpectrum(bytes, true, 0);
myArray = [];
for (var i:int = checkStart; i < checkLength; i+=8) // extract the sample
{
var sampleValue:Number = bytes.readFloat();
myArray.push(sampleValue);
}
if( CheckBeat( myArray ))
{
trace("here maybe a beat!!", getTimer());
}
}
function CheckBeat(valueArray:Array):Boolean // check the whether 'beat' exist
{
var meanValue:Number = valueArray[0];
for(var i:int = 1; i < valueArray.length; i++)
{
meanValue = (meanValue + valueArray[i])/2;
}
return meanValue > theshold;
}
function onPlaybackComplete(e:Event):void
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
But this method is just an Estimation, and not accurate enough at all.

AS3 - how to get mouse events on embedded bitmaps?

I'm embedding an image, creating a grid, and trying to cast each embedded image as a DisplayObject so I can use MouseEvents on each image in the grid, however, I can't get a mouseEvent to work. Any help is greatly appreciated. I think I'm missing something simple perhaps.
public class ImageGrid extends Sprite
{
private var gridItems:Array;
private var grid:Sprite;
private var sprite:Sprite
private var reveals:uint = 0;
private var exceededNumReveals:SimpleText;
[Embed(source="../Assets/images/tile-grad5-108.png")]
public var imgCls:Class;
public function ImageGrid(tileSize:Number, numTiles:Number, rows:Number)
{
gridItems = new Array();
grid = new Sprite();
addChild(grid);
for (var i:int = 0; i < numTiles; i++) {
gridItems[i] = new imgCls() as DisplayObject;
trace(gridItems[i] is DisplayObject) //true
gridItems[i].rotation = 180
gridItems[i].x = (i % rows) * (tileSize)
gridItems[i].y = int(i / rows) * (tileSize)
gridItems[i].addEventListener(MouseEvent.CLICK, gridItemClick, false, 0, false);
grid.addChild(gridItems[i]);
}
}
private function gridItemClick (event:MouseEvent):void {
trace(event.currentTarget);
reveals ++
if (reveals < AssetManager.numReveals) {
TweenLite.to(event.currentTarget, 0.5, {y:900,rotation:Math.random() * 360, ease:Sine.easeOut});
} else {
exceededNumReveals = new SimpleText ('You have exceeded your number of reveals', false, false, null, true, true, false, null, null, 20, 'right');
exceededNumReveals.y = this.y + 300;
exceededNumReveals.x = this.x + 30;
addChild(exceededNumReveals)
}
}
}
}
Here is how I fixed it:
public function ImageGrid(tileSize:Number, numTiles:Number, rows:Number)
{
gridItems = new Array();
grid = new Sprite();
addChild(grid);
for (var i:int = 0; i < numTiles; i++) {
var imageHolder:Sprite = new Sprite()
gridItems[i] = new imgCls() as DisplayObject;
gridItems[i].rotation = 180
gridItems[i].x = (i % rows) * (tileSize)
gridItems[i].y = int(i / rows) * (tileSize)
imageHolder.addChild(gridItems[i]);
imageHolder.addEventListener(MouseEvent.CLICK, gridItemClick, false, 0, false);
grid.addChild(imageHolder);
}
}
Wrap them in an interactive object (MovieClip, Sprite, etc.) to add a Mouse Click Event to them. Bitmaps are not interactive objects.
bitmaps are not interactive objects, you will have to add the listener to the parent

Actionscript, set objects invisible

This is a script for when i click an object, it opens a small book with some page flip effect.
I'm done with almost everything but i want that when i click in a back button everything desapears and i go back to only seeing the original object. It is not working because its only deleting one of the pages! I tried doing an array but it didnt work either and Im not very good with arrays too. Can anyone help?
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.display.Sprite;
import flash.display.Loader;
var cont : DisplayObject;
var cont2 : DisplayObject;
var imgLoader : Loader;
//loads pages
for (var i:int=0; i<=4; i++){
imgLoader = new Loader();
imgLoader.contentLoaderInfo.addEventListener(Event.INIT, onLoadJPEG);
imgLoader.load(new URLRequest(""+i+".png"));
}
var imgLoader2 : Loader;
//loads back button
imgLoader2 = new Loader();
imgLoader2.contentLoaderInfo.addEventListener(Event.INIT, onLoadSketch);
imgLoader2.load(new URLRequest("voltaatrassketchbook.png"));
function onLoadJPEG (e : Event) : void {
cont = e.target.loader;
cont.x =250;
cont.y =50;
cont.width = (445-100)/2;
cont.height = (604-100)/2;
addChild(cont);
cont.addEventListener(MouseEvent.MOUSE_UP, FlipPage);
}
function onLoadSketch (e : Event) : void {
cont2 = e.target.loader;
cont2.x =450;
cont2.y =300;
cont2.width = 181/2;
cont2.height = 127/2;
addChild(cont2);
cont2.addEventListener(MouseEvent.MOUSE_UP, volta);
}
function FlipPage(e:MouseEvent):void{
setChildIndex(DisplayObject(e.currentTarget), this.numChildren - 1);
if (e.currentTarget.rotationY == 0) {
var myTween:Tween = new Tween(e.currentTarget, "rotationY",
Regular.easeInOut,0, 180, 1, true);
}
if (e.currentTarget.rotationY == 180) {
var myTween:Tween = new Tween(e.currentTarget, "rotationY",
Regular.easeInOut, 180, 0, 1, true);
}
}
//function to go back
function volta (e: MouseEvent): void {
gotoAndStop(1);
cont.visible=false;
cont2.visible=false;
}
Option 1
You are right that you could use an array. Put this at the top of your code, before you start loading the pages:
var pages:Array = [];
Then put this as the final line inside onLoadJPEG()
pages.push(cont);
That will add each image to the array when it is loaded.
Then in volta() you can loop through the array and make each image invisible
for(var i:int = 0; i < pages.length; i++) {
DisplayObject(pages[i]).visible = false;
}
Option 2
Another approach would be to add all the images to a container Sprite and then all you would have to do is make the container Sprite invisible.
Add this to the top of your code before you load the pages :
var pages:Sprite = new Sprite();
addChild(pages);
Then in onLoadJPEG() add cont as a child of the container
pages.addChild(cont);
Then in volta() :
pages.visible = false;
If you use this approach, don't forget to call setChildIndex() on the container inside of FlipPage() :
pages.setChildIndex(DisplayObject(e.currentTarget), this.numChildren - 1);

How do I remove all instances called by the AddChild function?

I'm working on a sniper game and I'm trying to fix a issue I run into when I click the character to kill him. Anyways, long sotry short multiple instances of a MovieClip are created and I need them all to be removed at the same time when a if statement is executed. Is this possible, if so, what is the code?
Code:
stop();
Mouse.hide();
var blood:Array = [];
// after you create your clips your needing to keep track of.
var level_complete1:level_complete = new level_complete();
var ammo:Number = 5;
var cash:Number= 100;
var level:Number = 1;
var exp:Number = 0;
var blood_c:Number = 0;
var exp_needed = 25;
var dead_check:Number = 0; //Check to see if the target is dead
var check_blood:Number = 0; //Check to make sure blood doens't loop
var blood_splat1:blood_splat = new blood_splat();
blood.push(blood_splat1);
target1.addEventListener(MouseEvent.CLICK, target_shot);
function target_shot(event:MouseEvent):void{
if(dead_check==0){
addChild(blood_splat1);
blood_splat1.y = mouseY;
blood_splat1.x = mouseX;
target1.gotoAndPlay(32);
if (blood_splat1.currentFrame==6){
//blood_splat1.gotoAndStop(6);
//removeChild(blood_splat1);
cash=cash+150;
exp=exp+25;
ammo=ammo-1;
dead_check = 1;
blood_c = 1;
}
}
if (dead_check==1){
addChild(blood_splat1);
blood_splat1.y = mouseY;
blood_splat1.x = mouseX;
target1.gotoAndStop(38);
blood_c = 1;
//if (blood_splat1.currentFrame==6){
//blood_splat1.gotoAndStop(6);
if (blood_c==1){
for each(var mc:MovieClip in blood){
mc.parent.removeChild(mc);
blood.splice(blood.indexOf(mc), 1);
}
}
}
}
Edit:
Ok here is the problem I see from testing.
Your never getting blood_c set to 1 so it will never remove the blood splat. if you force it (for testing I forced it to = 1) you will never see the blood splat because it is removed instantly after it is created.
So my advice is when you first addChild(blood_splat1); you make a timer. or a frame counter. or something and when it counts down or fires (like a timer it calls a function to remove the blood splat. Like this:
stop();
Mouse.hide();
import flash.utils.Timer;
import flash.events.TimerEvent;
var bloodTimer:Timer = new Timer(1000, 1); // one second and doesn't repeat.
//var level_complete1:level_complete = new level_complete();
var ammo:Number = 5;
var cash:Number= 100;
var level:Number = 1;
var exp:Number = 0;
var blood_c:Number = 0;
var exp_needed = 25;
var dead_check:Number = 0; //Check to see if the target is dead
var check_blood:Number = 0; //Check to make sure blood doens't loop
var blood_splat1:blood_splat = new blood_splat();
target1.addEventListener(MouseEvent.CLICK, target_shot);
function removeBlood(te:TimerEvent):void
{
if(blood_splat1.parent != null && blood_splat1.parent.contains(blood_splat1))
{
blood_splat1.parent.removeChild(blood_splat1);
}
}
function target_shot(event:MouseEvent):void
{
if(dead_check==0)
{
addChild(blood_splat1);
bloodTimer.start();
bloodTimer.addEventListener(TimerEvent.TIMER_COMPLETE, removeBlood);
blood_splat1.y = mouseY;
blood_splat1.x = mouseX;
target1.gotoAndPlay(32);
if (blood_splat1.currentFrame==6)
{
//blood_splat1.gotoAndStop(6);
//removeChild(blood_splat1);
cash=cash+150;
exp=exp+25;
ammo=ammo-1;
dead_check = 1;
blood_c = 1;
}
}
if (dead_check==1)
{
addChild(blood_splat1);
bloodTimer.start();
bloodTimer.addEventListener(TimerEvent.TIMER_COMPLETE, removeBlood);
blood_splat1.y = mouseY;
blood_splat1.x = mouseX;
target1.gotoAndStop(38);
blood_c = 1;
//if (blood_splat1.currentFrame==6){
//blood_splat1.gotoAndStop(6);}
}
}
Down and dirty, you can do this (but it won't remove children of the children) :
while (numChildren > 0) {
removeChild(getChildAt(0));
}