« Return to Thread: Dynamic effects on a material

Re: removeChildByName??????????????

by zanemx :: Rate this Message:

Reply to Author | View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.
Help please....I can't remove my displayObject3Ds. Is this a know issue? I've tried 300 different ways......here is my code. What it does is fire bullets toward the top of the screen. I only what to display 10 bullets at a time..so I want to remove the ones I no longer need. Any thoughts paperVision makers?



package RWClass {
   
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.objects.parsers.Collada;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.materials.MovieMaterial;
    import org.papervision3d.core.proto.DisplayObjectContainer3D;
    import flash.display.Sprite;
    import flash.events.*;
    import fl.motion.*;
    import flash.utils.Timer;
    import fl.transitions.easing.*;
    import gs.*;

    public class Car extends DisplayObject3D {
       
        //private vars
        private var c:*;
        private var cCon:DisplayObject3D;
        private var pCon:DisplayObjectContainer3D;
        private var bulletTimer:Timer = new Timer(200);//bullets spawned    //fire bullets funct
        private var bulletTimer2:Timer = new Timer(100);//firing rate
        private var bullet:Sprite = new Bullet();
        private var randomX:Number = Math.floor(Math.random() * 700 - 350);
        private var p:Plane;
        private var planeArray:Array = new Array();
        private var bulletName:Number = 0;
        //vars passed from main for bullet x/y direction
        private var objX:Number;
        private var objZ:Number;
       
        //--CONSTRUCTOR
        public function Car(x:Number, z:Number) {
            //trace(x);
            //trace(z);
            objX = x;
            objZ = z;
            initalize();
        }//constructor
       
        //--INITALIZE
        private function initalize():void{
            pCon = new DisplayObjectContainer3D();
            //this.addChild(pCon);
            buildCars();
            addListeners();
        }
       
        //--ADD LISTENERS
        private function addListeners():void{
            bulletTimer.addEventListener(TimerEvent.TIMER, fireBullets);
            bulletTimer2.addEventListener(TimerEvent.TIMER, plotPath);
        }
       
        //--BUILD CARS
        private function buildCars():void {
            //var p:* = new Plane();//new MovieMaterial(dust, false, true, false), 700, 1000);
            c = new Collada("Assets/dae/car.dae");
            cCon = new DisplayObject3D();
            cCon.addChild(c);
            addChild(cCon);
            //var t:* = new Collada("Assets/dae/hturret.dae");
            //--PLANE
            /*with (p) {
                rotationX = 270;
                x = 0;
                y = 0;
                z = -1000;
            }*/
            //--CAR
            with (cCon) {
                scale = .1;//.1 is ideal
                y = -450;
                rotationY = 180;
                rotationX = 270;
                rotationZ = 180;
                x = randomX;
            }
            //--TURRET
            /*with (t) {
                scale = .035;
                x = -30;//side to side
                y = 207;//up and down
                z = -280;//front to back
                //rotationY = 120;
            }*/
           
            TweenLite.to(cCon, 7, {delay:0, y:Math.random()*350 - 300});
           
            bulletTimer.start();
        }//--buildCars end
       
//____________________________________________________________________
//                                             BULLETS

        //-------FIRE BULLETS
        private function fireBullets(e:TimerEvent):void{
            p = new Plane(new MovieMaterial(bullet, false, true, false), 50, 10);
            with (p) {
                        rotationX = 270;
                        rotationY = 90;
                        x = 0;
                        y = 0;
                        z = 0;
                       
            }
            //trace(p.name);
            var doCon:* = new DisplayObject3D();
            with(doCon){
                scale = .4;
                y = cCon.y;
                x = cCon.x;
                rotationX = 20;
                addChild(p);
                name = "bullet";
            }
            addChild(doCon);
            pCon.addChild(doCon);
            planeArray.push(doCon);
            bulletTimer2.start();
           
            //trace(c.numChildren);
            if(planeArray.length > 10){
                planeArray.shift();
                pCon.removeChild(getChildByName("bullet"));
                trace(pCon.numChildren);
            }
           
           
            bulletName++;
        }
       
        //-------PLOT BULLET PATH
        private function plotPath(e:TimerEvent):void{
           
            for(var i:Number = 0; i < planeArray.length; i++){
                planeArray[i].moveUp(10);
            }
        }
    }//class
}//package





Daniel O' Brian <daniel.obrian@...> wrote:
Try
 
removeChild(getChildByName(‘instanceName’));
 
or if you’re looping through a range of objects
 
var n:uint  = 1;
while(getChildByName(‘instanceName’+n) {
removeChild(getChildByName(‘instanceName’+n));
n++;
}
 
D

From: papervision3d-bounces@... [mailto:papervision3d-bounces@...] On Behalf Of Avery
Sent: 04 June 2008 09:11
To: papervision3d@...
Subject: [Papervision3D] removeChildByName??????????????
 
had anyone got the RemoveChildByName method of the DisplayObjectContainer3D class to work? I have been pulling my hair out trying to remove displayObject3D instances.

 

This email transmission is confidential and intended solely
for the person or organisation to whom it is addressed. If you
are not the intended recipient, you must not copy, distribute
or disseminate the information, or take any action in relation
to it and please delete this e-mail. Any views expressed in
this message are those of the individual sender, except where
the sender specifically states them to be the views of any
organisation or employer. If you have received this message
in error, do not open any attachment but please notify the
sender (above). This message has been checked for all known
viruses powered by Messagelabs. For further information
visit www.messagelabs.com/stats.asp Please rely on your own
virus check as no responsibility is taken by the sender for
any damage rising out of any virus infection this communication
may contain.

LIDA Ltd 36 Golden Square, Soho, London, W1F 9EE, United Kingdom
Reg No. 03860916, registered in the United Kingdom.
_______________________________________________
Papervision3D mailing list
Papervision3D@...
http://osflash.org/mailman/listinfo/papervision3d_osflash.org



My Portfolio Website


_______________________________________________
Papervision3D mailing list
Papervision3D@...
http://osflash.org/mailman/listinfo/papervision3d_osflash.org

 « Return to Thread: Dynamic effects on a material