dgfrench

AS3 sprite/interface issue

Jan 9th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import flash.display.Bitmap;
  4.     import flash.display.Sprite;
  5.     import flash.events.Event;
  6.    
  7.     import interfaces.ISprite;
  8.        
  9.     [SWF(width="600", height="400", backgroundColor="#cccccc", frameRate="60")]
  10.    
  11.     public class Main extends Sprite
  12.     {
  13.         private var _flakeList:Array;
  14.        
  15.         public function Main()
  16.         {
  17.             createWinter();
  18.             createFlakes(5);   
  19.         }
  20.        
  21.         private function createWinter():void
  22.         {
  23.             var bg:Bitmap = new Bitmap(new Winter(0, 0) ); //instantiate bitmap    
  24.             this.addChild(bg); //add bitmap to screen
  25.         }
  26.        
  27.         private function createFlakes(amt:int):void
  28.         {
  29.             _flakeList=[]; //instantiate array
  30.            
  31.             //loop to create flakes using var passed from above to determine how many
  32.             for (var i:int=0; i<amt; i++)
  33.             {
  34.                 var flake:Snowflake2 = new Snowflake2();
  35.                 flake.x = 50 + i*70; //position flakes across x axis
  36.                 flake.y = 50;
  37.                 flake.scaleX = flake.scaleY = .25; //scale flakes to 25%
  38.                 this.addChild(flake); //add flakes to screen
  39.                 _flakeList.push(flake);
  40.             }
  41.             this.addEventListener(Event.ENTER_FRAME, update);
  42.         }
  43.        
  44.         private function update(e:Event):void
  45.         {
  46.             //trace("work");
  47.             //loop thru array of flakes, run update for each one
  48.             for each(var flake:ISprite in _flakeList)
  49.             {
  50.                 flake.update();
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment