A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: movieclip not sprite

  1. #1
    Senior Member
    Join Date
    Aug 2006
    Posts
    293

    movieclip not sprite

    hi all,

    i am hoping someone can give me a clue on how to swap the sprite instance for a movieclip via the document class.

    this a boid example from soulwire, and works great but i want to use a library clip instead of the vector sprite - for arguments sake - the library clip would be "boid"...

    PHP Code:
    package  
    {
        
    import soulwire.ai.Boid;

        
    import flash.display.Sprite;
        
    import flash.events.Event;
        
    import flash.geom.Vector3D;

        
    /**
         * Demo
         */

        
    [SWF(width="800"height="600"backgroundColor="#FFFFFF"frameRate="31")]
        public class 
    AbstractDemo extends Sprite 
        
    {
            protected var 
    _boids Vector.<Boid> = new Vector.<Boid>();
            protected var 
    _boidHolder Sprite;

            protected var 
    _config Object = {
                                                
    minForce:3.0,
                                                
    maxForce:6.0,
                                                
    minSpeed:6.0,
                                                
    maxSpeed:12.0,
                                                
    minWanderDistance:10.0,
                                                
    maxWanderDistance:100.0,
                                                
    minWanderRadius:5.0,
                                                
    maxWanderRadius:20.0,
                                                
    minWanderStep:0.1,
                                                
    maxWanderStep:0.9,
                                                
    boundsRadius:250,
                                                
    numBoids:120
                                                
    };

            public function 
    AbstractDemo()
            {
                
    _boidHolder addChild(new Sprite()) as Sprite;
                
    addEventListener(Event.ADDED_TO_STAGEonAddedToStage);
            }
            
            protected function 
    init():void
            
    {
                
    // Init
            
    }

            protected function 
    createBoid() : Boid
            
    {
                var 
    boid Boid = new Boid();
                
                
    setProperties(boid);
                
    boid.renderData boid.createDebugShape0000004.02.0);
                
                
    _boids.push(boid);
                
    _boidHolder.addChild(boid.renderData);
                
                return 
    boid;
            }

            protected function 
    createBoids(count int):void
            
    {
                for (var 
    int 0;counti++)
                {
                    
    createBoid();
                }
            }

            protected function 
    setProperties(boid Boid) : void
            
    {
                
    boid.edgeBehavior Boid.EDGE_BOUNCE;
                
    boid.maxForce random(_config.minForce_config.maxForce);
                
    boid.maxSpeed random(_config.minSpeed_config.maxSpeed);
                
    boid.wanderDistance random(_config.minWanderDistance_config.maxWanderDistance);
                
    boid.wanderRadius random(_config.minWanderRadius_config.maxWanderRadius);
                
    boid.wanderStep random(_config.minWanderStep_config.maxWanderStep);
                
    boid.boundsRadius stage.stageWidth 0.6;
                
    boid.boundsCentre = new Vector3D(stage.stageWidth >> 1stage.stageHeight >> 10.0);
                
                if(
    boid.== && boid.== 0)
                {
                    
    boid.boid.boundsCentre.random(-100100);
                    
    boid.boid.boundsCentre.random(-100100);
                    
    boid.random(-100100);
                    
                    var 
    vel Vector3D = new Vector3D(random(-22), random(-22), random(-22));
                    
    boid.velocity.incrementBy(vel);
                }
            }

            protected function 
    randommin Numbermax Number NaN ) : Number
            
    {
                if ( 
    isNaN(max) )
                {
                    
    max min;
                    
    min 0;
                }
                
                return 
    Math.random() * ( max min ) + min;
            }

            protected function 
    updateBoid(boid Boidindex int) : void
            
    {
                
    // Override
            
    }

            protected function 
    step(event Event null) : void
            
    {
                for (var 
    int 0;_boids.lengthi++)
                {
                    
    updateBoid(_boids[i], i);
                }
            }

            protected function 
    onAddedToStage(event Event) : void
            
    {
                
    removeEventListener(Event.ADDED_TO_STAGEonAddedToStage);
                
    addEventListener(Event.ENTER_FRAMEstep);
                
    init();
            }
        }

    i know that i need to add
    PHP Code:
        import flash.display.Movieclip
    but am not able to work out what i need to add/edit...

    any ideas folks?

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Which thing are you trying to replace?
    If you mean you want to replace Boid with something, then you'll have to either change the definition of Boid or extend it with a new class. Boid is not just graphics, it has properties and methods that this class relies on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center