1/3, 18«123»

Kingfo新词 --- 舰人

2010-3-30 9:46:57 原创 抢沙发(0)

 舰人   ---      指装备先进的弄潮儿,偶尔有炫耀的成分

[原]Flash对象在(x)HTML中的格式和参数及安全性

2010-3-15 9:29:54 原创 抢沙发(1)

 这是份总结,有不正确的地方请见谅。

联系方式: KingFo     oicuicu@gmail.com

================
已更新团队共享PPT中
================

===============

 

有点悲剧的是当PPT导入到 Google Docs 中后畸形了许多。。。将就看吧=。=

 全屏可能会好一点

 或者点此处:http://docs.google.com/present/view?id=dcvxfmd9_37fk9bxgfq&interval=10 

 

[原]安全使用随机类方法

2008-12-18 20:09:37 原创 抢沙发(0)

在前面 一篇文章《[原]一种随机类的方法》中提到的关于使用 getDefinitionByName() 方法获取类,但是在文章的最后的问题,不知道有没有人思考过这样做为什么特殊。

这里公布答案:

getDefinitionByName()  它将直接从当前应用程序域(ApplicationDomain)去查询并获取,因此当我们Load,一个swf执行时,会报错。

有时候对于多层次的应用程序域(相当于应用程序域的树,层次>=3)管理起来会非常麻烦。

因此我们需要单独提取出LoaderContext 管理他们,通过LoaderContext的applicationDomain中getDefinition()来管理它们。例如 单例模式。

道理弄懂了,实现起来就是很简单的东西了。

 

[原]一种随机类的方法

2008-11-26 11:22:13 原创 抢沙发(1)

此类方法用于类似图片的类进行随机实力化,或者拥有同个接口或同个父类的功能函数,实现某种随机

当然,这里随机的方式不做讨论,可以参阅之前本人的 48位线性同余算法的 [原]关于股子系统的优化

完整代码:
 

  1. package  {  
  2.     import flash.utils.getDefinitionByName;  
  3.       
  4.     /**  
  5.      * ...  
  6.      * @author Telds[KingFo]  
  7.      */ 
  8.     public class SampleImage {  
  9.           
  10.         [Embed(source = '../assets/building/image0.png')]public static const BUILDING_0:Class;  
  11.         [Embed(source = '../assets/building/image1.png')]public static const BUILDING_1:Class;  
  12.         [Embed(source = '../assets/building/image2.png')]public static const BUILDING_2:Class;  
  13.         [Embed(source = '../assets/building/image3.png')]public static const BUILDING_3:Class;  
  14.         [Embed(source = '../assets/building/image4.png')]public static const BUILDING_4:Class;  
  15.         [Embed(source = '../assets/building/image5.png')]public static const BUILDING_5:Class;  
  16.         [Embed(source = '../assets/building/image6.png')]public static const BUILDING_6:Class;  
  17.         [Embed(source = '../assets/building/image7.png')]public static const BUILDING_7:Class;  
  18.         [Embed(source = '../assets/building/image8.png')]public static const BUILDING_8:Class;  
  19.         [Embed(source = '../assets/building/image9.png')]public static const BUILDING_9:Class;  
  20.         [Embed(source = '../assets/building/image10.png')]public static const BUILDING_10:Class;  
  21.         [Embed(source = '../assets/building/image11.png')]public static const BUILDING_11:Class;  
  22.         [Embed(source = '../assets/building/image12.png')]public static const BUILDING_12:Class;  
  23.           
  24.         public static function getRandomImageClass():Class {  
  25.             var n:String = "SampleImage_BUILDING_";  
  26.             var i:int = Math.random() * 12;  
  27.             n = n.concat(i);  
  28.             return getDefinitionByName(n) as Class;  
  29.         }  
  30.           
  31.     }  
  32.       

至于如何知道完全限定类名

可以使用以下类进行测试获取,这里值得一提的是我上面的写法是比较特殊例子,至于为什么特殊就留着看客您琢磨了~~~
 

  1. flash.utils.getQualifiedClassName ()  

 

[原]APNGDecoder---AS3实现进行中

2008-11-16 23:12:17 原创 抢沙发(0)

目前进度50%

已完成数据解码和校验~~~~ 不过目前还是体力活~~~

接下来是还原图片。。。。。。哎,周末结束了.............真不知道我下次有时间是什么时候了。。

以下是测试代码,工程截图............. 哦 对了,这个所谓的 1455049.png就是前篇博文:APNG?
中插入图片,我之所以写这段解码器目的其实只是想让IE也能预览APNG而已........哎.....
不知道哪位同学有APNG解码器的代码呢?有的话可以告诉我声哦~~~

  1. public function Main():void {  
  2.             var l:URLLoader = new URLLoader();  
  3.             l.dataFormat = URLLoaderDataFormat.BINARY;  
  4.             l.addEventListener(Event.COMPLETE, handleURLloader);  
  5.             l.load(new URLRequest("../image/1455049.png"));  
  6.             }  
  7.           
  8.         private function handleURLloader(e:Event):void {  
  9.             apngdecoder.decode(e.target.data)  
  10.             trace(apngdecoder.getResult().getTotalFrames())  
  11.             trace(apngdecoder.getResult().getWidth())  
  12.             trace(apngdecoder.getResult().getWidth())  
  13.             trace(apngdecoder.getResult().getBitDepth())  
  14.               
  15.                           
  16.         } 

 

[原]CRC32校验类AS3实现

2008-11-15 15:32:28 原创 抢沙发(0)

因为需要用到CRC32的算法,所以改写了下原来as3corelib 的 CRC算法,单独提出来作为一个类,当然您也可以 搜索 "Sample Cyclic Redundancy Code implementation" 找到 ISO C [ISO-9899] 的C语言描述。
下面我都会帖出:

本人的类:

  1. package  {  
  2.     import flash.utils.ByteArray;  
  3.       
  4.     /**  
  5.      * CRC 32位 校验类  
  6.      * 与JAVA的CRC32类似  
  7.      * 算法参考自 as3corelib http://code.google.com/p/as3corelib/    
  8.      * 的 PNGEncoder.as 中CRC算法部分  
  9.      * @author Telds[KingFo]  
  10.      * @version 0.0.1  
  11.      * @example  
  12.      * var bytes:ByteArray = new ByteArray();  
  13.      * var crc32:CRC32 = new CRC32();  
  14.      * var str:String="kingfo";  
  15.      * bytes.writeUTFBytes(str);  
  16.      * crc32.update(bytes);  
  17.      * trace(crc32);  
  18.      */ 
  19.     public class CRC32 {  
  20.         public static const POLYNOMIAL:uint = 0xEDB88320;  
  21.         /**  
  22.          * 创建获取CRC表  
  23.          * @return  
  24.          */ 
  25.         public static function getCrcTable():Array {  
  26.             /* Make the table for a fast CRC. */ 
  27.             if (!crcTableComputed) {  
  28.                 crcTable = new Array(256);  
  29.                 var c:uint;  
  30.                 for (var i:uint=0; i < 256; i++) {  
  31.                     c = i;  
  32.                     for (var j:uint=0; j < 8; j++) {  
  33.                         c = (c & 1) ? (c >>> 1) ^ POLYNOMIAL : (c >>> 1);  
  34.                     }  
  35.                     crcTable[i] = c;  
  36.                 }  
  37.                 crcTableComputed = true;  
  38.             }             
  39.             return crcTable;  
  40.         }  
  41.         /**  
  42.          * 构造函数,实例化同时产生CRC表  
  43.          */ 
  44.         public function CRC32() {  
  45.             getCrcTable();  
  46.         }         
  47.         /**  
  48.          * 更新CRC  
  49.          * @param   bytes                   指定更新的字节流  
  50.          * @param   offset                  偏移量,默认从 bytes.position=0 开始  
  51.          * @param   length                  长度,默认为0,即指定更新的字节流的长度          
  52.          */ 
  53.         public function update(bytes:ByteArray, offset:int=0,length:int=0):void {  
  54.             length = length > 0 ? length : bytes.length;  
  55.             var c:uint = ~value;  
  56.             for (var i:int = offset; i < length; i++) {  
  57.                 c = crcTable[(c ^ bytes[i]) & 0xFF] ^ (c >>> 8);  
  58.             }  
  59.             value = ~c;  
  60.         }  
  61.         /**  
  62.          * 获取结果  
  63.          * @return  
  64.          */ 
  65.         public function getValue():uint {  
  66.             return value & 0xFFFFFFFF;  
  67.         }  
  68.         /**  
  69.          * 重置结果  
  70.          */ 
  71.         public function reset():void {  
  72.             value = 0x00000000;  
  73.         }  
  74.           
  75.         public function toString():String {  
  76.             var v:uint = getValue();  
  77.             return "0x"+v.toString(16).toUpperCase();  
  78.         }  
  79.           
  80.           
  81.  
  82.         private var value:uint = 0x00000000;          
  83.         /* Table of CRCs of all 8-bit messages. */ 
  84.         private static var crcTable:Array;  
  85.         /* Flag: has the table been computed? Initially false. */ 
  86.         private static var crcTableComputed:Boolean = false;  
  87.           
  88.           
  89.     }  
  90.       

PNGEncoder.as 中CRC 核心代码部分:
 

  1. if (!crcTableComputed) {  
  2.             crcTableComputed = true;  
  3.             crcTable = [];  
  4.             var c:uint;  
  5.             for (var n:uint = 0; n < 256; n++) {  
  6.                 c = n;  
  7.                 for (var k:uint = 0; k < 8; k++) {  
  8.                     if (c & 1) {  
  9.                         c = uint(uint(0xedb88320) ^   
  10.                             uint(c >>> 1));  
  11.                     } else {  
  12.                         c = uint(c >>> 1);  
  13.                     }  
  14.                 }  
  15.                 crcTable[n] = c;  
  16.             }  
  17.         }  
  18. /////  
  19. c = 0xffffffff;  
  20.         for (var i:int = 0; i < (e-p); i++) {  
  21.             c = uint(crcTable[  
  22.                 (c ^ png.readUnsignedByte()) &   
  23.                 uint(0xff)] ^ uint(c >>> 8));  
  24.         }  
  25.         c = uint(c^uint(0xffffffff)); 

Sample Cyclic Redundancy Code implementation
 

  1. /* Table of CRCs of all 8-bit messages. */ 
  2.    unsigned long crc_table[256];  
  3.      
  4.    /* Flag: has the table been computed? Initially false. */ 
  5.    int crc_table_computed = 0;  
  6.      
  7.    /* Make the table for a fast CRC. */ 
  8.    void make_crc_table(void)  
  9.    {  
  10.      unsigned long c;  
  11.      int n, k;  
  12.      
  13.      for (n = 0; n < 256; n++) {  
  14.        c = (unsigned long) n;  
  15.        for (k = 0; k < 8; k++) {  
  16.          if (c & 1)  
  17.            c = 0xedb88320L ^ (c >> 1);  
  18.          else 
  19.            c = c >> 1;  
  20.        }  
  21.        crc_table[n] = c;  
  22.      }  
  23.      crc_table_computed = 1;  
  24.    }  
  25.     
  26.  
  27.    /* Update a running CRC with the bytes buf[0..len-1]--the CRC  
  28.       should be initialized to all 1's, and the transmitted value  
  29.       is the 1's complement of the final running CRC (see the  
  30.       crc() routine below). */ 
  31.      
  32.    unsigned long update_crc(unsigned long crc, unsigned char *buf,  
  33.                             int len)  
  34.    {  
  35.      unsigned long c = crc;  
  36.      int n;  
  37.      
  38.      if (!crc_table_computed)  
  39.        make_crc_table();  
  40.      for (n = 0; n < len; n++) {  
  41.        c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);  
  42.      }  
  43.      return c;  
  44.    }  
  45.      
  46.    /* Return the CRC of the bytes buf[0..len-1]. */ 
  47.    unsigned long crc(unsigned char *buf, int len)  
  48.    {  
  49.      return update_crc(0xffffffffL, buf, len) ^ 0xffffffffL;  
  50.    }  
  51.  

 

[原]一种猥琐的图片跨域的方法

2008-11-13 19:28:25 原创 抢沙发(2)

今天看到达达(ASFlex)的博文,关于跨域的问题,突然想起来我之前[原]淘宝店家起义篇。。。要做的实验之一,遂趁当前下班时间,在公司里写了一段测试代码。

果然是无法Draw的,在帮助文档已经明确的写了......................................

如何突破呢? 还是以后直接拿TextField来用?

以此标记,下回,改用AVM1+AVM2混合内容测试

目前方法是猥琐的抽出Loader来用

测试连接:
www.xintend.com/temp/icd/index.html

有兴趣的同学可以去玩下~~ 图片可以拖动~~~~~~~

核心 代码部分:
 

  1.  function handleLoadBtn():void {  
  2.             var s:String = urlInput.text;  
  3.             var ht:String = "<img src='";  
  4.             if (s.length > 0) {  
  5.                 ht += s;                                  
  6.                 ht += "' ";  
  7.                 ht += "id='image'>";  
  8.                 tf.htmlText = ht;  
  9.                 output.text = ht;  
  10.                 output.text += "\n";                  
  11.                 output.text += tf.getImageReference("image");  
  12.                 var c:DisplayObject = tf.getImageReference("image");  
  13.                 ui.addChild(c);  
  14.                 output.text += "\n ui.addChild(c);";  
  15.             }  
  16.         } 

 

[原]视觉模型心得---第二次扩展及补充

2008-11-9 20:48:30 原创 抢沙发(0)

本次主要针对了上回模型总结的补充和扩展,上回的解释可以参看这篇陋文:
[原]视觉模型心得

本次纠正模型如下(点击图片看大图):
还是需要等待时间和实践的验证~~~



 

1/3, 18«123»