<ActionScript 3 Bible 2nd>读书笔记(13,14,16,21)

Binary Types in ActionScript

A read-only stream, like a  URLStream, would only implement  IDataInput. A read-write stream, like Socket, implements both.


Read   or  write  an  ActionScript  object using  AMF    encoding.    Specify   AMF0  or AMF3  using  the  objectEncoding  parameter. 


In Flash Player 10 and later, you can clear out a  ByteArray with the  clear() method.  


position determines where objects will be read starting from, and read operations will automatically advance the position to the end of the last read object.
length reports, in bytes, the total size of the  ByteArray.


have an exact duplicate of the original object, not merely another reference 

     import flash.utils.ByteArray; 
           var arrayA:Array = new Array("a", "b", "c", "d";); 
           var byteArray:ByteArray = new ByteArray(); 
           byteArray.writeObject(arrayA); 
           byteArray.position = 0; 
           var arrayB:Array = byteArray.readObject(); 
           arrayB.push("e", "", "g", "h"); 
           trace(arrayA.join(" "));           //a b c d 
           trace(arrayB.join(" "));           //a b c d e f g h 
         }
There is one important consideration when you are copying objects of custom types. Byte arrays write data using AMF, which natively supports standard ActionScript data types, but not custom classes. ( AMF is the Action Message Format, a binary protocol) That means that, by default, if you write an object of a custom type, it is written to the byte array correctly, but it is stored as a generic object. Therefore,when you retrieve it from a byte array you cannot cast it back to the correct type. You can fix this by using the   registerClassAlias() function.


Note 
The AIR runtime can have multiple stages because every top-level window has its own display list.  


交换两个显示对象的深度

 	stage.setChildIndex(apple, 0); 
       stage.setChildIndex(carrot, 1); 
       //now carrot is definitively on top of apple 
       stage.swapChildren(apple, carrot); //now apple is on top 
       stage.swapChildren(apple, carrot); //now carrot is back on top 
       //note that swapping again puts things the way they were 
       stage.swapChildrenAt(0, 1); 

You can investigate the contents and organization of a display list. You can test whether one display object contains another: 

       carrot.addChild(sprouts); 
       trace(carrot.contains(sprouts)); //true 


 wmodeGPU— In Flash Player 10.0.32 and later, this read-only Boolean flag indicates whether the GPU is performing compositing. This property will be true only if GPU compositing is actively in use: if you’ve indicated that the GPU wmode should be used in your embed parameters or at SWF publish time, and if it is supported by the hardware Flash Player is running  on. When this is true, you may be able to crank up the graphics without dropping frame rate.  If you have this graphics-intensive of an application, you would do well to keep track of other  performance metrics while you adjust. 


Using Assets from a SWF 

   package { 
      import com.actionscriptbible.Example; 
      import flash.display.DisplayObject; 
      import flash.display.Loader; 
      import flash.events.Event; 
      import flash.net.URLRequest; 
      import flash.system.ApplicationDomain; 
      public class ch16ex1 extends Example { 
        protected var loader:Loader; 
        public function ch16ex1() { 
          trace("Loading assets..."); 
           loader = new Loader(); 
           loader.load(new URLRequest( 
             "http://actionscriptbible.com/files/ch16assets.swf")); 
           loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad); 
        } 
        protected function onLoad(event:Event):void { 
          try { 
             var assetsDomain:ApplicationDomain = 
               loader.contentLoaderInfo.applicationDomain; 
             var FishingCatClass:Class = 
               Class(assetsDomain.getDefinition("assets.FishingCat")); 
             var cat:DisplayObject = new FishingCatClass(); 
             cat.y = 100; 
             addChild(cat); 
             trace("added fishing cat!"); 
           } catch (error:Error) { 
             trace(error); 
           } 
        } 
      } 
   } 

double clicking

double-clicks is off by default.

     doubleClickEnabled = true; 
     addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClick); 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值