home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Templates / Flash / flashmo_101_3d_carousel / org / papervision3d / materials / BitmapAssetMaterial.as next >
Text File  |  2007-07-18  |  4KB  |  123 lines

  1. /*
  2.  *  PAPER    ON   ERVIS  NPAPER ISION  PE  IS ON  PERVI IO  APER  SI  PA
  3.  *  AP  VI  ONPA  RV  IO PA     SI  PA ER  SI NP PE     ON AP  VI ION AP
  4.  *  PERVI  ON  PE VISIO  APER   IONPA  RV  IO PA  RVIS  NP PE  IS ONPAPE
  5.  *  ER     NPAPER IS     PE     ON  PE  ISIO  AP     IO PA ER  SI NP PER
  6.  *  RV     PA  RV SI     ERVISI NP  ER   IO   PE VISIO  AP  VISI  PA  RV3D
  7.  *  ______________________________________________________________________
  8.  *  papervision3d.org ∩┐╜ blog.papervision3d.org ∩┐╜ osflash.org/papervision3d
  9.  */
  10.  
  11. /*
  12.  * Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
  13.  *
  14.  * Permission is hereby granted, free of charge, to any person
  15.  * obtaining a copy of this software and associated documentation
  16.  * files (the "Software"), to deal in the Software without
  17.  * restriction, including without limitation the rights to use,
  18.  * copy, modify, merge, publish, distribute, sublicense, and/or sell
  19.  * copies of the Software, and to permit persons to whom the
  20.  * Software is furnished to do so, subject to the following
  21.  * conditions:
  22.  *
  23.  * The above copyright notice and this permission notice shall be
  24.  * included in all copies or substantial portions of the Software.
  25.  *
  26.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27.  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  28.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29.  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  30.  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  31.  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  32.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  33.  * OTHER DEALINGS IN THE SOFTWARE.
  34.  */
  35.  
  36. // __________________________________________________________________________ BITMAP ASSET MATERIAL
  37.  
  38. package org.papervision3d.materials
  39. {
  40. import flash.display.BitmapData;
  41. import flash.utils.describeType;
  42. import flash.utils.getDefinitionByName;
  43.  
  44.  
  45. /**
  46. * The BitmapAssetMaterial class creates a texture from a Bitmap library symbol.
  47. *
  48. * Materials collects data about how objects appear when rendered.
  49. *
  50. */
  51. public class BitmapAssetMaterial extends BitmapMaterial
  52. {
  53.     // ______________________________________________________________________ NEW
  54.  
  55.     /**
  56.     * The BitmapAssetMaterial class creates a texture from a Bitmap library asset.
  57.     *
  58.     * @param    id                    The linkage name of the Bitmap symbol in the library.
  59.     * @param    initObject            [optional] - An object that contains additional properties with which to populate the newly created material.
  60.     */
  61.  
  62.     public function BitmapAssetMaterial( id:String, initObject:Object=null )
  63.     {
  64.         super( id, initObject );
  65.     }
  66.  
  67.  
  68.     // ______________________________________________________________________ CREATE BITMAP
  69.  
  70.     /**
  71.     * [internal-use]
  72.     *
  73.     * @param    asset
  74.     * @return
  75.     */
  76.     protected override function createBitmap( asset:* ):BitmapData
  77.     {
  78.         // Remove previous bitmap
  79.         if( this._texture != asset )
  80.         {
  81.             _count[this._texture]--;
  82.  
  83.             var prevBitmap:BitmapData = _library[this._texture];
  84.  
  85.             if( prevBitmap && _count[this._texture] == 0 )
  86.                 prevBitmap.dispose();
  87.         }
  88.  
  89.         // Retrieve from library or...
  90.         var bitmapOk :BitmapData;
  91.         var bitmap   :BitmapData = _library[asset];
  92.  
  93.         // ...loadBitmap
  94.         if( ! bitmap )
  95.         {
  96.             var BitmapAsset:Class = getDefinitionByName( asset ) as Class;
  97.  
  98.             var description:XML = describeType( BitmapAsset );
  99.  
  100.             // Check if Flash 9 Alpha
  101.             if( description..constructor.length() == 0 )
  102.                 bitmap = new BitmapAsset() as BitmapData;
  103.             else
  104.                 bitmap = new BitmapAsset( 0, 0 ) as BitmapData;
  105.  
  106.             bitmapOk = correctBitmap( bitmap, true );
  107.  
  108.             _library[asset] = bitmapOk;
  109.             _count[asset] = 0;
  110.         }
  111.         else
  112.         {
  113.             bitmapOk = bitmap;
  114.             _count[asset]++;
  115.         }
  116.  
  117.         return bitmapOk;
  118.     }
  119.  
  120.     static private var _library :Object = new Object();
  121.     static private var _count   :Object = new Object();
  122. }
  123. }