错误描述

flex在加载module时报出如题所示的错误,

实际表现

问题就出现在这 我取消这个错误提示框 再次在前台查询数据 就一切ok

问题就出现在这一句

var zoufangModel:ZfRecord=ZfRecord(data);

调试

第一次是这样 继续就出抛出错误

取消错误再次查询 调试的结果就是这样

多了个[inherited] 确实第二次是正常的 但为什么第一次不行 到现在也不明白

解决方法

将错误的那一句改成

var zoufangModel:ZfRecord = ObjectTranslator.objectToInstance( data, ZfRecord ) as ZfRecord;

ObjectTranslator类的代码如下

/*

* Copyright (c) 2006 Darron Schall <darron@darronschall.com>

*

* Permission is hereby granted, free of charge, to any person

* obtaining a copy of this software and associated documentation

* files (the "Software"), to deal in the Software without

* restriction, including without limitation the rights to use,

* copy, modify, merge, publish, distribute, sublicense, and/or sell

* copies of the Software, and to permit persons to whom the

* Software is furnished to do so, subject to the following

* conditions:

*

* The above copyright notice and this permission notice shall be

* included in all copies or substantial portions of the Software.

*

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,

* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES

* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND

* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT

* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,

* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR

* OTHER DEALINGS IN THE SOFTWARE.

*/

package com.common.util

{

    

    import flash.net.ObjectEncoding;

    import flash.net.registerClassAlias;

    import flash.utils.ByteArray;

    import flash.utils.describeType;

    import flash.utils.getDefinitionByName;

    

    /**

     * Utility class to convert vanilla objects to class instances.

     */

    public final class ObjectTranslator

    {

        

        /**

         * Converts a plain vanilla object to be an instance of the class

         * passed as the second variable.  This is not a recursive funtion

         * and will only work for the first level of nesting.  When you have

         * deeply nested objects, you first need to convert the nested

         * objects to class instances, and then convert the top level object.

         *

         * TODO: This method can be improved by making it recursive.  This would be

         * done by looking at the typeInfo returned from describeType and determining

         * which properties represent custom classes.  Those classes would then

         * be registerClassAlias'd using getDefinititonByName to get a reference,

         * and then objectToInstance would be called on those properties to complete

         * the recursive algorithm.

         *

         * @param object The plain object that should be converted

         * @param clazz The type to convert the object to

         */

        public static function objectToInstance( object:Object, clazz:Class ):*

        {

            var bytes:ByteArray = new ByteArray();

            bytes.objectEncoding = ObjectEncoding.AMF0;

            

            // Find the objects and byetArray.writeObject them, adding in the

            // class configuration variable name -- essentially, we're constructing

            // and AMF packet here that contains the class information so that

            // we can simplly byteArray.readObject the sucker for the translation

            

            // Write out the bytes of the original object

            var objBytes:ByteArray = new ByteArray();

            objBytes.objectEncoding = ObjectEncoding.AMF0;

            objBytes.writeObject( object );

            

            // Register all of the classes so they can be decoded via AMF

            var typeInfo:XML = describeType( clazz );

            var fullyQualifiedName:String = typeInfo.@name.toString().replace( /::/, "." );

            registerClassAlias( fullyQualifiedName, clazz );

            

            // Write the new object information starting with the class information

            var len:int = fullyQualifiedName.length;

            bytes.writeByte( 0x10 );  // 0x10 is AMF0 for "typed object (class instance)"

            bytes.writeUTF( fullyQualifiedName );

            // After the class name is set up, write the rest of the object

            bytes.writeBytes( objBytes, 1 );

            

            // Read in the object with the class property added and return that

            bytes.position = 0;

            

            // This generates some ReferenceErrors of the object being passed in

            // has properties that aren't in the class instance, and generates TypeErrors

            // when property values cannot be converted to correct values (such as false

            // being the value, when it needs to be a Date instead).  However, these

            // errors are not thrown at runtime (and only appear in trace ouput when

            // debugging), so a try/catch block isn't necessary.  I'm not sure if this

            // classifies as a bug or not... but I wanted to explain why if you debug

            // you might seem some TypeError or ReferenceError items appear.

            var result:* = bytes.readObject();

            return result;

        }

        

    } // end class

} // end package

参考资料

http://blog.163.com/hongwei_benbear/blog/static/118395291201122612328768/

flex 强制转换类型失败无法将object转换为XXX的更多相关文章

  1. TypeError: Error #1034: 强制转换类型失败:无法将 "" 转换为 Array。

    1.错误描述 TypeError: Error #1034: 强制转换类型失败:无法将 "" 转换为 Array. at mx.charts.series::LineSeries/ ...

  2. TypeError: Error #1034: 强制转换类型失败:无法将 "0.49" 转换为 mx.graphics.IFill。

    1.错误描述 TypeError: Error #1034: 强制转换类型失败:无法将 "0.49" 转换为 mx.graphics.IFill. at mx.charts.ser ...

  3. TypeError: Error #1034: 强制转换类型失败:无法将 mx.controls::DataGrid@9a7c0a1 转换为 spark.core.IViewport。

    1.错误描述 TypeError: Error #1034: 强制转换类型失败:无法将 mx.controls::DataGrid@9aa90a1 转换为 spark.core.IViewport. ...

  4. TypeError: Error #1034: 强制转换类型失败:无法将 flash.events::MouseEvent@73b7cc1 转换为 mx.events.ItemClickEvent。

    1.错误描述 TypeError: Error #1034: 强制转换类型失败:无法将 flash.events::MouseEvent@73b7cc1 转换为 mx.events.ItemClick ...

  5. Flash Professional 报错 TypeError: Error #1034: 强制转换类型失败:无法将 xxxx@zzzz 转换为 yyy

    通常是因为xxx yyy 两个不同链接名的元件 使用了同一个属性名

  6. Web | JavaScript的引用数据类型强制转换类型

    我在这里主要的想提下的是JavaScript中的引用类型进行强制转换类型.因为对于基本数据类型的变换大多都是雷同的,很容易熟知,但是引用数据类型有一点小插曲. JavaScript的引用类型主要为对象 ...

  7. PHP强制转换类型

    PHP强制转换类型   获取数据类型 : 1.如果想查看某个表达式的值和类型,用var_dump(). 2.如果只是想得到一个易读懂的类型的表达方式用于调试,用 gettype().3.要查看某个类型 ...

  8. 简述Java变量和强制转换类型

    简述Java变量和强制转换类型 java变量 1. java变量 变量:顾名思义,就是在java执行程序过程中可以发生改变的量,就好比方程式中的未知数X一样. 变量的内存分配过程 int a ; // ...

  9. C++ 4 种具有更 为准确语义的新强制转换类型

    1. static_cast<T>() 可用于把指向A 的指针强制转换为指向B 的指针,其约束条件是类B必须是类A的子类.例如:A *obj = new B;B *b = static_c ...

随机推荐

  1. WPF ViewModel与多个View绑定后如何解决的问题

    当重复创建View并绑定同一个ViewModel后,ViewModel中的字段更新,在新的View中的没有反应或者在View中找不到相应的视觉树(如ListBox的ListBoxItem) 初始的解决 ...

  2. 四种方式实现子goroutine与主线程的同步

    如何实现子goroutine与主线程的同步 第一种方式: 这种方式很太死板,就不演示了. 第二种方式:使用 channel机制,每个 goroutine传一个 channel进去然后往里写数据,在再主 ...

  3. iOS Push详述,了解一下?

    WeTest 导读 本文主要对iOS Push的在线push.本地push及离线(远程)push进行梳理,介绍了相关逻辑,测试时要注意的要点以及相关工具.小小的Push背后蕴藏着大大的逻辑! Push ...

  4. Dubbo介绍和服务架构分析

    Dubbo是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和Spring框架无缝集成.使用zookeeper作为服务的注册中心,对外提供服务 ...

  5. 修改apache默认主页,重定向404页面

    yum 下载apache后默认主页 默认配置文件: vim /etc/httpd/conf/httpd.conf /etc/httpd/conf.d/welcome.conf 跳转页面到 /var/w ...

  6. 南京邮电大学java程序设计作业在线编程第五次作业

    王利国的"Java语言程序设计第5次作业(2018)"详细 主页 我的作业列表 作业结果详细 总分:100 选择题得分:50  1. 以下哪一个工具是Java的编译器?( ) A. ...

  7. PHP MySQL 简介

    PHP MySQL 简介 通过 PHP,您可以连接和操作数据库. MySQL 是跟 PHP 配套使用的最流行的开源数据库系统. 如果想学习更多 MySQL 知识可以查看本站MySQL 教程. MySQ ...

  8. Docker服务端防护

    运行一个容器或应用程序的核心是通过 Docker 服务端.Docker 服务的运行目前需要 root 权限,因此其安全性十分关键. 首先,确保只有可信的用户才可以访问 Docker 服务.Docker ...

  9. Programming In Scala笔记-第六章、函数式对象

    这一章主要是以定义和完善一个有理数类Rational为线索,分析和介绍有关类定义,构造函数,方法重写,变量定义和私有化,以及对操作符的定义等. 一.Rational类定义和构造函数 1.定义一个空类 ...

  10. 一道有趣的Twitter技术面试题

    来自:http://blog.jobbole.com/50705/ 看下面这个图片” “在这个图片里我们有不同高度的墙.这个图片由一个整数数组所代表,数组中每个数是墙的高度.上边的图可以表示为数组[2 ...