1/30, 235«1234»

另一种对象深度比较方法---as3实现

2011-12-7 11:00:24 开发者 抢沙发(0)

 我们要比较2个对象的内容是否相同,即深度比较的方法可以用MD5等算法实现。

以下是代码片段:

  var a:Object = new Object();

a.b = [1, 2, 3];
a.c = { };
a.c.a = ''
var b:Object = { };
b.b = [1, 2, 3];
b.c = { };
b.c.a = '';
var abytes:ByteArray = new ByteArray();
var bbytes:ByteArray = new ByteArray();
abytes.writeObject(a);
abytes.position = 0;
bbytes.writeObject(b);
bbytes.position = 0;
trace(a == b); //false
trace(abytes.toString() == bbytes.toString()) // true
trace(MD5.hashBytes(abytes) == MD5.hashBytes(bbytes)); //true

 

 

ImageLoader初代开发完毕

2011-6-28 16:36:37 AnyLoader 抢沙发(1)

 ImageLoader 是图像下载器, Anyloader 系列的一个子集, AnyLoader 是多个 flash 实例组合的,由 JS 封装的套件的称呼,在需要调用的情况进行按需调用。

如图:

Anyloader 扩展愿景

 

  • 尽可能的早的获得加载内容信息。
  • 尽可能早的处理加载的内容。
  • 实现预加载。
  • 提升页面性能。

 

因此Imageloader就是

 

  • 尽可能的早的获得图片高宽等信息。
  • 尽可能早的处理加载的图片
  • 实现图片预加载。
  • 提升页面加载图片的性能。

 

imageloader 封装代码

https://github.com/kissyteam/kissy-ajbridge/tree/master/src/imageloader

imageloader AS3 核心代码

https://github.com/kingfo/anyloader

 

Base64字节流方式实现

2011-5-28 16:07:59 算法 抢沙发(0)

Kingfo 注:

1. 以下类来自dynamicflash 值得参考,其实改造成  readMultiByte  和 writeMultiByte 会更好。

 这样就可以改造支持更广泛:

encode(string:String,targetCharsets:String='UTF-8',sourceCharsets:String = 'UTF-8' );

 

2. 以下类 >> 更改为 >>> 可能更严谨,但与 >>> 相对的  <<< 运算符并不提供,因此采用了 << 和 >> 。

 package com . dynamicflash . util {     
    
    
import flash . utils . ByteArray ;     
         
    
public class Base64 {     
             
        
private static const BASE64_CHARS : String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" ;     
    
        
public static const version : String = "1.0.0" ;     
    
        
public static function encode ( data : String ): String {     
            
// Convert string to ByteArray      
            
var bytes : ByteArray = new ByteArray ();     
            bytes
 . writeUTFBytes ( data );     
                 
            
// Return encoded ByteArray      
            
return encodeByteArray ( bytes );     
        
}     
             
        
public static function encodeByteArray ( data : ByteArray ): String {     
            
// Initialise output      
            
var output : String = "" ;     
                 
            
// Create data and output buffers      
            
var dataBuffer : Array ;     
            
var outputBuffer : Array = new Array ( 4 );    // Kingfo : 6位 和 8位的公倍数正好是 24 ,因此需要 4个6位空间。
                 
            
// Rewind ByteArray      
            data
 . position = 0 ;     
                 
            
// while there are still bytes to be processed      
            
while ( data . bytesAvailable > 0 ) {     
                
// Create new data buffer and populate next 3 bytes from data      
                dataBuffer 
= new Array ();     
                
for ( var i : uint = 0 ; < 3 && data . bytesAvailable > 0 ; i ++) {     
                    dataBuffer
 [ i ] = data . readUnsignedByte ();     
                
}     
                     
                
// Convert to data buffer Base64 character positions and      
                
// store in output buffer      
                outputBuffer
 [ 0 ] = ( dataBuffer [ 0 ] & 0xfc ) >> 2 ;  // kingfo: 很多同学会直接 >>2 ,这样不严谨。  这里做的非常好。这里只保留前6位。
                outputBuffer
 [ 1 ] = (( dataBuffer [ 0 ] & 0x03 ) << 4 ) | (( dataBuffer [ 1 ]) >> 4 );     
                outputBuffer
 [ 2 ] = (( dataBuffer [ 1 ] & 0x0f ) << 2 ) | (( dataBuffer [ 2 ]) >> 6 );     
                outputBuffer
 [ 3 ] = dataBuffer [ 2 ] & 0x3f ;     
                     
                
// If data buffer was short (i.e not 3 characters) then set      
                
// end character indexes in data buffer to index of '=' symbol.      
                
// This is necessary because Base64 data is always a multiple of      
                
// 4 bytes and is basses with '=' symbols.      
                
for ( var j : uint = dataBuffer . length ; < 3 ; j ++) {     
                    outputBuffer
 [ + 1 ] = 64 ;     
                
}     
                     
                
// Loop through output buffer and add Base64 characters to      
                
// encoded data string for each character.      
                
for ( var k : uint = 0 ; < outputBuffer . length ; k ++) {     
                    output 
+= BASE64_CHARS . charAt ( outputBuffer [ k ]);     
                
}     
            
}     
                 
            
// Return encoded data      
            
return output ;     
        
}     
             
        
public static function decode ( data : String ): String {     
            
// Decode data to ByteArray      
            
var bytes : ByteArray = decodeToByteArray ( data );     
                 
            
// Convert to string and return      
            
return bytes . readUTFBytes ( bytes . length );     
        
}     
             
        
public static function decodeToByteArray ( data : String ): ByteArray {     
            
// Initialise output ByteArray for decoded data      
            
var output : ByteArray = new ByteArray ();     
                 
            
// Create data and output buffers      
            
var dataBuffer : Array = new Array ( 4 );     
            
var outputBuffer : Array = new Array ( 3 );     
    
            
// While there are data bytes left to be processed      
            
for ( var i : uint = 0 ; < data . length ; += 4 ) {     
                
// Populate data buffer with position of Base64 characters for      
                
// next 4 bytes from encoded data      
                
for ( var j : uint = 0 ; < 4 && + < data . length ; j ++) {     
                    dataBuffer
 [ j ] = BASE64_CHARS . indexOf ( data . charAt ( + j ));     
                
}     
                     
                
// Decode data buffer back into bytes      
                outputBuffer
 [ 0 ] = ( dataBuffer [ 0 ] << 2 ) + (( dataBuffer [ 1 ] & 0x30 ) >> 4 );     
                outputBuffer
 [ 1 ] = (( dataBuffer [ 1 ] & 0x0f ) << 4 ) + (( dataBuffer [ 2 ] & 0x3c ) >> 2 );             
                outputBuffer
 [ 2 ] = (( dataBuffer [ 2 ] & 0x03 ) << 6 ) + dataBuffer [ 3 ];     
                     
                
// Add all non-padded bytes in output buffer to decoded data      
                
for ( var k : uint = 0 ; < outputBuffer . length ; k ++) {     
                    
if ( dataBuffer [ k + 1 ] == 64 ) break ;     
                    output
 . writeByte ( outputBuffer [ k ]);     
                
}     
            
}     
                 
            
// Rewind decoded data ByteArray      
            output
 . position = 0 ;     
                 
            
// Return decoded data      
            
return output ;     
        
}     
             
        
public function Base64 () {     
            
throw new Error ( "Base64 class is static container only" );     
        
}     
    
}     
}  

一两件可以预见的事情

2011-5-27 9:46:26 心得 抢沙发(0)
  •  apple终端设备,尤其是移动设备,如果在中国突出硬件价格的因素,必然会像当年windows统治中国寻常百姓一样。
  • android 系统是突然杀入搅局的家伙,不过持长尾理论战群雄到是在这片国都可能得胜的,如果当年学习当年的MTK通用系统山寨机占领农民工一样,且android的出生于较为厚实的家庭,必然比MTK会走的更宽泛的路线。

一句话,未来是apple的 也是 android。但最终是 android的,只是最早占领的是apple的

LOL

规范说明书几个词

2010-12-29 9:46:46 开发者 抢沙发(5)

 强调依次降降级

  • MUST /  MUST NOT  / REQUIRED / SHALL / SHALL NOT
  • SHOULD / SHOULD NOT / RECOMMENDED
  • MAY / OPTIONAL

 1. MUST   This word, or the terms "REQUIRED" or "SHALL", mean that the

   definition is an absolute requirement of the specification.
 
2. MUST NOT   This phrase, or the phrase "SHALL NOT", mean that the
   definition is an absolute prohibition of the specification.
 
3. SHOULD   This word, or the adjective "RECOMMENDED", mean that there
   may exist valid reasons in particular circumstances to ignore a
   particular item, but the full implications must be understood and
   carefully weighed before choosing a different course.
 
4. SHOULD NOT   This phrase, or the phrase "NOT RECOMMENDED" mean that
   there may exist valid reasons in particular circumstances when the
   particular behavior is acceptable or even useful, but the full
   implications should be understood and the case carefully weighed
   before implementing any behavior described with this label.
 
5. MAY   This word, or the adjective "OPTIONAL", mean that an item is
   truly optional.  One vendor may choose to include the item because a
   particular marketplace requires it or because the vendor feels that
   it enhances the product while another vendor may omit the same item.
   An implementation which does not include a particular option MUST be
   prepared to interoperate with another implementation which does
   include the option, though perhaps with reduced functionality. In the
   same vein an implementation which does include a particular option
   MUST be prepared to interoperate with another implementation which
   does not include the option (except, of course, for the feature the
   option provides.)
 

Flash前端开发者必备工具

2010-12-13 11:59:51 开发者 抢沙发(0)
1/30, 235«1234»