BulkLoader类和PV3D

AS3取消了movieclip的loader类,所以加载图片除了用

img =  new Loader ( );
img. load ( new URLRequest ( "assets/materials/c.png" ) );
//加载完成后的事件响应
img. contentLoaderInfo. addEventListener (Event. COMPLETE, setup );

就没有其他办法了,特别在要载入大量图片的环境下,就很难使用。
前几天发现了BulkLoader,大大简化了载入图片所需的步骤。而且可以对应各种格式,比如xml,video,声音,图片等文件。下面这个例子就是和pv3d结合使用的例子。
<object class="embedflash" width="425" height="355" data="http://www.lotloft.com/share/CubeWithDifferentSides.swf" type="application/x-shockwave-flash"> </object>

package  {
  import flash. display. Bitmap;
  import flash. display. BitmapData;
  import flash. events. Event;
  import br. com. stimuli. loading. BulkErrorEvent;
  import br. com. stimuli. loading. BulkLoader;
  import br. com. stimuli. loading. BulkProgressEvent;
  import org. papervision3d. lights. PointLight3D;
  import org. papervision3d. materials. BitmapMaterial;
  import org. papervision3d. materials. shaders. PhongShader;
  import org. papervision3d. materials. shaders. ShadedMaterial;
  import org. papervision3d. materials. shaders. Shader;
  import org. papervision3d. materials. utils. MaterialsList;
  import org. papervision3d. objects. primitives. Cube;
  import org. papervision3d. view. BasicView;
  [SWF ( width= "640"height= "480"backgroundColor= "#000000", frameRate= "60" ) ];
  public  class CubeWithDifferentSides  extends BasicView  {
   private  var light:PointLight3D;
   private  var cube:Cube;
   //loading class
   public  var loader : BulkLoader =  new BulkLoader ( "main-site" );
   public  function CubeWithDifferentSides ( )  {
    // Load images data
   loadImagesData ( );
   }
   private  function loadImagesData ( ): void  {
    //var loader : BulkLoader = new BulkLoader("main-site");
   loader. add ( "images/back.jpg"{id: "back" } );
   loader. add ( "images/bottom.jpg"{id: "bottom" } );
   loader. add ( "images/front.jpg"{id: "front" } );
   loader. add ( "images/left.jpg"{id: "left" } );
   loader. add ( "images/right.jpg"{id: "right" } );
   loader. add ( "images/top.jpg"{id: "top" } );   
   loader. addEventListener (BulkLoader. COMPLETE, onAllLoaded );   
   loader. start ( );
   }
  
   public  function onAllLoaded (evt:Event  ): void  {
    var materialsList:MaterialsList =  new MaterialsList ( );
   light =  new PointLight3D ( );
   materialsList. addMaterial (createShadedMaterial (loader. getBitmap ( "back" ) )"back" );
   materialsList. addMaterial (createShadedMaterial (loader. getBitmap ( "bottom" ) )"bottom" );
   materialsList. addMaterial (createShadedMaterial (loader. getBitmap ( "front" ) )"front" );
   materialsList. addMaterial (createShadedMaterial (loader. getBitmap ( "left" ) )"left" );
   materialsList. addMaterial (createShadedMaterial (loader. getBitmap ( "right" ) ), "right" );
   materialsList. addMaterial (createShadedMaterial (loader. getBitmap ( "top" ) )"top" );
   cube =  new Cube (materialsList,  500500500555 );
   scene. addChild (cube );
   startRendering ( );
   }
   private  function createShadedMaterial (bitmap:Bitmap ):ShadedMaterial  {
    trace (bitmap )
    var bitmapMaterial:BitmapMaterial =  new BitmapMaterial (bitmap. bitmapDatatrue );
    var shader:Shader =  new PhongShader (light, 0xffffff, 0x333333,  10, bitmap. bitmapData, bitmap. bitmapData );
    var shadedMaterial:ShadedMaterial =  new ShadedMaterial (bitmapMaterial, shader );
    return shadedMaterial;
   }
  override protected  function onRenderTick (event:Event= null ): void  {
   cube. rotationY +=  (viewport. containerSprite. mouseX - cube. rotationY ) * . 1;
   cube. rotationX +=  (viewport. containerSprite. mouseY - cube. rotationX ) * . 1;
   renderer. renderScene (scene,  camera, viewport );
   }
  }
}

你可能感兴趣的:(xml,Flash)