- 浏览: 782403 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (360)
- Java (101)
- JPA/Hibernate (10)
- Spring (14)
- Flex/BlazeDS (37)
- Database (30)
- Lucene/Solr/Nutch (0)
- Maven/Ant (25)
- CXF/WebService (3)
- RPC/RMI/SOAP/WSDL (1)
- REST (6)
- TDD/BDD/JUnit (1)
- Servlet/JSP (2)
- AI/MachineLearning (3)
- Resource (1)
- 字符编码 (2)
- OOA/OOPS/UML (5)
- DesignPattern (8)
- 算法与数据结构 (11)
- Web&App Server (13)
- 并发&异步&无阻塞 (7)
- Entertainment (4)
- JavaScript/ExtJS (45)
- CodeStyle&Quality (1)
- svn/git/perforce (8)
- JSON (2)
- JavaScriptTesting (4)
- Others (6)
- RegularExpression (2)
- Linux/Windows (12)
- Protocal (2)
- Celebrities (1)
- Interview (1)
- 计算机语言 (1)
- English (2)
- Eclipse (5)
- TimeZone/时区 (1)
- Finance (1)
- 信息安全 (1)
- JMS/MQ (2)
- XSD/XML/DTD (3)
- Android (4)
- 投资 (3)
- Distribution (3)
- Excel (1)
最新评论
-
qdujunjie:
如果把m换成具体的数字,比如4或者5,会让读者更明白
m阶B树中“阶”的含义 -
java-admin:
不错,加油,多写点文章
关于Extjs的mixins和plugin -
xiehuaidong880827:
你好,我用sencha cmd打包完本地工程后,把app.js ...
ExtJS使用Sencha Cmd合并javascript文件为一个文件 -
KIWIFLY:
lwpan 写道inverse = "true&qu ...
Hibernate中什么时候使用inverse=true -
luedipiaofeng:
good
消除IE stop running this script弹出框
Getting the class from an object
Class(getDefinitionByName(getQualifiedClassName(obj)));
Getting Class info of an Object in Flex
Frequently we may come across one requirement when we will be having one object and we want to know which class this object belongs to. In java, its as simple as object. getClass();
Flex also provides us with a class, mx.utils.ObjectUtil, which we can use for this purpose.
ObjectUtil.getClassInfo(object)
will return information about the class, and properties of the class, for the specified Object.
• name: String containing the name of the class;
• Properties: Sorted list of the property names of the specified object.
These are the properties we can use for that.
Alert.show(ObjectUtil.getClassInfo(faultEvent.target).name);
It’s often useful to know which class had generated some fault event and we can use the above code
How to instantiate Class from Class Name
One frequently asked question is how to instantiate a Class if you don't know the Class until runtime. The "new" operator simply operates on a Class. There's no reason that class has to be hard coded. It could be a variable of Class type. The trick then becomes setting the variable. Often this is done by using getDefintionByName () as below:
However this requires you to have the fully qualified name. Sometimes this isn't practical. You could thus do something simpler which requires a little more hard coding:
Lastly, any classes that are dynamically instantiated have to have been compiled into the SWF (or retrieved from a module/RSL/etc). Simply importing a Class does not accomplish this. (Importing is simply a way so you don't have to write the package name in front of the class every time.) There are three main ways (that I know of) to link a Class into a project.
The first is the method is to use the Class somewhere in the code. Examples of this include (as above) defining a variable of the class type or assigning the Class to a variable of type Class. Another example is rschmidt's comment below that you can instantiate an array that holds the classes.
The second method is to use the extraClass property of the Frame or Mixin tag. Warning, these methods may cause linkage problems.
Lastly, you can use the compiler options (how boring).
Personally, I think I prefer rschmidt's method. It's the most economical with code (and probably other resources as well).
Class(getDefinitionByName(getQualifiedClassName(obj)));
Getting Class info of an Object in Flex
Frequently we may come across one requirement when we will be having one object and we want to know which class this object belongs to. In java, its as simple as object. getClass();
Flex also provides us with a class, mx.utils.ObjectUtil, which we can use for this purpose.
ObjectUtil.getClassInfo(object)
will return information about the class, and properties of the class, for the specified Object.
• name: String containing the name of the class;
• Properties: Sorted list of the property names of the specified object.
These are the properties we can use for that.
Alert.show(ObjectUtil.getClassInfo(faultEvent.target).name);
It’s often useful to know which class had generated some fault event and we can use the above code
How to instantiate Class from Class Name
One frequently asked question is how to instantiate a Class if you don't know the Class until runtime. The "new" operator simply operates on a Class. There's no reason that class has to be hard coded. It could be a variable of Class type. The trick then becomes setting the variable. Often this is done by using getDefintionByName () as below:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" applicationComplete="init()"> <mx:Script> <![CDATA[ import flash.utils.getDefinitionByName; import myPackage.mySubPackage.MyClass; // all classes you may want to instantiate should be imported. import myPackage.mySubPackage.MyClass2; // all classes you may want to instantiate should be imported. public var dummy:MyClass; // forces "MyClass" to be linked in by the complier"; public var dummy:MyClass2; // forces "MyClass2" to be linked in by the complier"; public function init():void { var className:String; if (true) { // really this should be a useful conditional className = "myPackage.mySubPackage.MyClass"; //use fully qualified name } else { className = "myPackage.mySubPackage.MyClass2"; //use fully qualified name } var definition:Class = getDefinitionByName(className) as Class; // get class var myInstance:Object = new definition(); // create new instance of the class of type MyClass } ]]> </mx:Script> </mx:Application>
However this requires you to have the fully qualified name. Sometimes this isn't practical. You could thus do something simpler which requires a little more hard coding:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" applicationComplete="init()"> <mx:Script> <![CDATA[ import flash.utils.getDefinitionByName; import myPackage.mySubPackage.MyClass; import myPackage.mySubPackage.MyClass2; public function init():void { var definition:Class; if (true) { // really this should be a useful conditional definition = myClass; } else { definition = myClass2 } var myInstance:Object = new definition(); // create new instance of the class of type MyClass } ]]> </mx:Script> </mx:Application>
Lastly, any classes that are dynamically instantiated have to have been compiled into the SWF (or retrieved from a module/RSL/etc). Simply importing a Class does not accomplish this. (Importing is simply a way so you don't have to write the package name in front of the class every time.) There are three main ways (that I know of) to link a Class into a project.
The first is the method is to use the Class somewhere in the code. Examples of this include (as above) defining a variable of the class type or assigning the Class to a variable of type Class. Another example is rschmidt's comment below that you can instantiate an array that holds the classes.
The second method is to use the extraClass property of the Frame or Mixin tag. Warning, these methods may cause linkage problems.
Lastly, you can use the compiler options (how boring).
Personally, I think I prefer rschmidt's method. It's the most economical with code (and probably other resources as well).
发表评论
-
Panel高度为0但里面的组件依旧显示
2013-04-24 14:34 1078解决办法: 把Panel中的内容组件用<s:Scroll ... -
约束布局constraint layout
2013-03-01 14:02 1781约束布局constraint layout要点: 1)只有支持 ... -
根据屏幕分辨率动态调整组件大小
2013-02-22 17:34 1508将代码写在组件的preInitialize事件监听器里面 简化 ... -
设置Flex组件的尺寸大小
2013-02-21 16:17 1526深红色部分标明了需注意的地方 另外要注意组件和容器的生命周 ... -
Flex minWidth minHeight
2013-02-04 16:17 1511minWidth 这个值并不是给组件自己用的,而是给组件的父容 ... -
ActionScript遍历绑定(BindProperty,BindSetter,ChangeWatcher)
2013-02-01 10:11 2438注意: 为防止内存益处,记得调用watcherInstance ... -
Flex程序适应不同屏幕尺寸和分辨率(滚动条)
2013-01-31 15:02 9750FlashBuilder编译后自动生成的xx.html里面定义 ... -
FlexContext, FlexClient,FlexSession
2013-01-15 15:05 2358使用了BlazeDS后,可以从FlexContext中获取一系 ... -
防止RemoteObject批处理AMF消息
2013-01-14 17:01 1249问题描述: 如果你在短时内调用同一个java对象上的两个方法, ... -
自动检测http和https的RemoteObject
2013-01-13 10:30 1723package { import util.Bro ... -
flex浏览器相关辅组类
2012-12-06 13:39 1245package util { import flash. ... -
Flex可变参数带来的问题
2012-12-06 13:34 1477当你在flex的方法中用了可变参数后,你会发现这些参数传到ja ... -
flexlib的treeGrid用法
2012-11-30 13:46 1257为了使用treeGrid,通常你需要定义自己的DataDesc ... -
自定义flex tree的DataDescriptor
2012-11-30 13:42 1397public class EnvironmentDataDes ... -
关于Boolean类型在flex与java中间传递的问题
2012-11-30 13:38 1245/** *为简化,只列举两个字段 */ publi ... -
给Flex的Tree赋值方式(XML和ArrayCollection)
2012-11-30 09:33 40131)方式一,mxml内嵌xml数据赋值方式,Embedded ... -
Custom Alert
2012-11-26 19:21 0<?xml version="1.0&qu ... -
Flex服务端分页
2012-11-14 17:00 1043Structure: model event ... -
Flex可携带数据的Aler组件(DataCarriableAlert)
2012-11-14 16:52 1304package component.alert { ... -
映射flex类到java内部类
2012-11-14 16:05 1165java端 public class Person{ p ...
相关推荐
嗯 关于廖雪峰老师网站的学习笔记---flex弹性盒子实例篇
FLEX中文教程+实例
Flex模块化开发实例adsfasdfasdfasdfasdfasdfasdfjasdjfasdjf按时大法师的发生地方
这个实例是我看到得flex+hibernate 最经典的实例
一个完整的Flex+Java登录实例,基于Flex框架
这是一些简单的flex实例,有利于初级学习flex的人学习。
使用httpService通过xml传递对象的时候,用于flex端解析xml的实例。
flex和php结合实例,通过这个例子你可以很快地构建自己的flex和php应用程序
flex弹性盒子布局实例,本次博客实例需要的一些资源,源代码,可自行下载研究,一起进步,共勉,一起加油
该项目提供flex调用百度地图,并提供相关实例
flex4 摄像头调用实例 很有参考价值
flex画图板实例 源码 flex画图板实例 源码 flex画图板实例 源码 flex画图板实例 源码flex画图板实例 源码
一个flex+java的登录实例完整版+flex框架 一个flex+java的登录实例完整版+flex框架
项目的一部分源码flex+java,项目的一部分源码flex+java,项目的一部分源码flex+java,
java flex开发项目配置实例教程,图文并茂教您快速搭建java flex开发工程。
Flex 图片上传 实例 源码Flex图片上传实例
MyEclipse插件flex安装及简单实例MyEclipse插件flex安装及简单实例MyEclipse插件flex安装及简单实例
flex动态加载css实例flex动态加载css实例flex动态加载css实例
Flex4 spring整合实例,采用了spring-flex-1.0.3.RELEASE-with-dependencies包
Flex源码大合集可以直接将文件导入到Flex中,都是as的项目。我使用的是Flex4.5,其中如果缺少swc包,可以从所有的swc文件里面找