舰人 --- 指装备先进的弄潮儿,偶尔有炫耀的成分
这是份总结,有不正确的地方请见谅。
联系方式: KingFo oicuicu@gmail.com
================
已更新团队共享PPT中
================
===============

有点悲剧的是当PPT导入到 Google Docs 中后畸形了许多。。。将就看吧=。=
全屏可能会好一点
或者点此处:http://docs.google.com/present/view?id=dcvxfmd9_37fk9bxgfq&interval=10
在前面 一篇文章《[原]一种随机类的方法》中提到的关于使用 getDefinitionByName() 方法获取类,但是在文章的最后的问题,不知道有没有人思考过这样做为什么特殊。
这里公布答案:
getDefinitionByName() 它将直接从当前应用程序域(ApplicationDomain)去查询并获取,因此当我们Load,一个swf执行时,会报错。
有时候对于多层次的应用程序域(相当于应用程序域的树,层次>=3)管理起来会非常麻烦。
因此我们需要单独提取出LoaderContext 管理他们,通过LoaderContext的applicationDomain中getDefinition()来管理它们。例如 单例模式。
道理弄懂了,实现起来就是很简单的东西了。
此类方法用于类似图片的类进行随机实力化,或者拥有同个接口或同个父类的功能函数,实现某种随机
当然,这里随机的方式不做讨论,可以参阅之前本人的 48位线性同余算法的 [原]关于股子系统的优化
完整代码:
- package {
- import flash.utils.getDefinitionByName;
- /**
- * ...
- * @author Telds[KingFo]
- */
- public class SampleImage {
- [Embed(source = '../assets/building/image0.png')]public static const BUILDING_0:Class;
- [Embed(source = '../assets/building/image1.png')]public static const BUILDING_1:Class;
- [Embed(source = '../assets/building/image2.png')]public static const BUILDING_2:Class;
- [Embed(source = '../assets/building/image3.png')]public static const BUILDING_3:Class;
- [Embed(source = '../assets/building/image4.png')]public static const BUILDING_4:Class;
- [Embed(source = '../assets/building/image5.png')]public static const BUILDING_5:Class;
- [Embed(source = '../assets/building/image6.png')]public static const BUILDING_6:Class;
- [Embed(source = '../assets/building/image7.png')]public static const BUILDING_7:Class;
- [Embed(source = '../assets/building/image8.png')]public static const BUILDING_8:Class;
- [Embed(source = '../assets/building/image9.png')]public static const BUILDING_9:Class;
- [Embed(source = '../assets/building/image10.png')]public static const BUILDING_10:Class;
- [Embed(source = '../assets/building/image11.png')]public static const BUILDING_11:Class;
- [Embed(source = '../assets/building/image12.png')]public static const BUILDING_12:Class;
- public static function getRandomImageClass():Class {
- var n:String = "SampleImage_BUILDING_";
- var i:int = Math.random() * 12;
- n = n.concat(i);
- return getDefinitionByName(n) as Class;
- }
- }
- }
至于如何知道完全限定类名
可以使用以下类进行测试获取,这里值得一提的是我上面的写法是比较特殊例子,至于为什么特殊就留着看客您琢磨了~~~
- flash.utils.getQualifiedClassName ()
目前进度50%
已完成数据解码和校验~~~~ 不过目前还是体力活~~~
接下来是还原图片。。。。。。哎,周末结束了.............真不知道我下次有时间是什么时候了。。
以下是测试代码,工程截图............. 哦 对了,这个所谓的 1455049.png就是前篇博文:APNG?
中插入图片,我之所以写这段解码器目的其实只是想让IE也能预览APNG而已........哎.....
不知道哪位同学有APNG解码器的代码呢?有的话可以告诉我声哦~~~
- public function Main():void {
- var l:URLLoader = new URLLoader();
- l.dataFormat = URLLoaderDataFormat.BINARY;
- l.addEventListener(Event.COMPLETE, handleURLloader);
- l.load(new URLRequest("../image/1455049.png"));
- }
- private function handleURLloader(e:Event):void {
- apngdecoder.decode(e.target.data)
- trace(apngdecoder.getResult().getTotalFrames())
- trace(apngdecoder.getResult().getWidth())
- trace(apngdecoder.getResult().getWidth())
- trace(apngdecoder.getResult().getBitDepth())
- }
因为需要用到CRC32的算法,所以改写了下原来as3corelib 的 CRC算法,单独提出来作为一个类,当然您也可以 搜索 "Sample Cyclic Redundancy Code implementation" 找到 ISO C [ISO-9899] 的C语言描述。
下面我都会帖出:
本人的类:
- package {
- import flash.utils.ByteArray;
- /**
- * CRC 32位 校验类
- * 与JAVA的CRC32类似
- * 算法参考自 as3corelib http://code.google.com/p/as3corelib/
- * 的 PNGEncoder.as 中CRC算法部分
- * @author Telds[KingFo]
- * @version 0.0.1
- * @example
- * var bytes:ByteArray = new ByteArray();
- * var crc32:CRC32 = new CRC32();
- * var str:String="kingfo";
- * bytes.writeUTFBytes(str);
- * crc32.update(bytes);
- * trace(crc32);
- */
- public class CRC32 {
- public static const POLYNOMIAL:uint = 0xEDB88320;
- /**
- * 创建获取CRC表
- * @return
- */
- public static function getCrcTable():Array {
- /* Make the table for a fast CRC. */
- if (!crcTableComputed) {
- crcTable = new Array(256);
- var c:uint;
- for (var i:uint=0; i < 256; i++) {
- c = i;
- for (var j:uint=0; j < 8; j++) {
- c = (c & 1) ? (c >>> 1) ^ POLYNOMIAL : (c >>> 1);
- }
- crcTable[i] = c;
- }
- crcTableComputed = true;
- }
- return crcTable;
- }
- /**
- * 构造函数,实例化同时产生CRC表
- */
- public function CRC32() {
- getCrcTable();
- }
- /**
- * 更新CRC
- * @param bytes 指定更新的字节流
- * @param offset 偏移量,默认从 bytes.position=0 开始
- * @param length 长度,默认为0,即指定更新的字节流的长度
- */
- public function update(bytes:ByteArray, offset:int=0,length:int=0):void {
- length = length > 0 ? length : bytes.length;
- var c:uint = ~value;
- for (var i:int = offset; i < length; i++) {
- c = crcTable[(c ^ bytes[i]) & 0xFF] ^ (c >>> 8);
- }
- value = ~c;
- }
- /**
- * 获取结果
- * @return
- */
- public function getValue():uint {
- return value & 0xFFFFFFFF;
- }
- /**
- * 重置结果
- */
- public function reset():void {
- value = 0x00000000;
- }
- public function toString():String {
- var v:uint = getValue();
- return "0x"+v.toString(16).toUpperCase();
- }
- private var value:uint = 0x00000000;
- /* Table of CRCs of all 8-bit messages. */
- private static var crcTable:Array;
- /* Flag: has the table been computed? Initially false. */
- private static var crcTableComputed:Boolean = false;
- }
- }
PNGEncoder.as 中CRC 核心代码部分:
- if (!crcTableComputed) {
- crcTableComputed = true;
- crcTable = [];
- var c:uint;
- for (var n:uint = 0; n < 256; n++) {
- c = n;
- for (var k:uint = 0; k < 8; k++) {
- if (c & 1) {
- c = uint(uint(0xedb88320) ^
- uint(c >>> 1));
- } else {
- c = uint(c >>> 1);
- }
- }
- crcTable[n] = c;
- }
- }
- /////
- c = 0xffffffff;
- for (var i:int = 0; i < (e-p); i++) {
- c = uint(crcTable[
- (c ^ png.readUnsignedByte()) &
- uint(0xff)] ^ uint(c >>> 8));
- }
- c = uint(c^uint(0xffffffff));
Sample Cyclic Redundancy Code implementation
- /* Table of CRCs of all 8-bit messages. */
- unsigned long crc_table[256];
- /* Flag: has the table been computed? Initially false. */
- int crc_table_computed = 0;
- /* Make the table for a fast CRC. */
- void make_crc_table(void)
- {
- unsigned long c;
- int n, k;
- for (n = 0; n < 256; n++) {
- c = (unsigned long) n;
- for (k = 0; k < 8; k++) {
- if (c & 1)
- c = 0xedb88320L ^ (c >> 1);
- else
- c = c >> 1;
- }
- crc_table[n] = c;
- }
- crc_table_computed = 1;
- }
- /* Update a running CRC with the bytes buf[0..len-1]--the CRC
- should be initialized to all 1's, and the transmitted value
- is the 1's complement of the final running CRC (see the
- crc() routine below). */
- unsigned long update_crc(unsigned long crc, unsigned char *buf,
- int len)
- {
- unsigned long c = crc;
- int n;
- if (!crc_table_computed)
- make_crc_table();
- for (n = 0; n < len; n++) {
- c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
- }
- return c;
- }
- /* Return the CRC of the bytes buf[0..len-1]. */
- unsigned long crc(unsigned char *buf, int len)
- {
- return update_crc(0xffffffffL, buf, len) ^ 0xffffffffL;
- }
今天看到达达(ASFlex)的博文,关于跨域的问题,突然想起来我之前[原]淘宝店家起义篇。。。要做的实验之一,遂趁当前下班时间,在公司里写了一段测试代码。
果然是无法Draw的,在帮助文档已经明确的写了......................................
如何突破呢? 还是以后直接拿TextField来用?
以此标记,下回,改用AVM1+AVM2混合内容测试
目前方法是猥琐的抽出Loader来用
测试连接:
www.xintend.com/temp/icd/index.html
有兴趣的同学可以去玩下~~ 图片可以拖动~~~~~~~
核心 代码部分:
- function handleLoadBtn():void {
- var s:String = urlInput.text;
- var ht:String = "<img src='";
- if (s.length > 0) {
- ht += s;
- ht += "' ";
- ht += "id='image'>";
- tf.htmlText = ht;
- output.text = ht;
- output.text += "\n";
- output.text += tf.getImageReference("image");
- var c:DisplayObject = tf.getImageReference("image");
- ui.addChild(c);
- output.text += "\n ui.addChild(c);";
- }
- }