- 浏览: 804392 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (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 1119解决办法: 把Panel中的内容组件用<s:Scroll ... -
约束布局constraint layout
2013-03-01 14:02 1859约束布局constraint layout要点: 1)只有支持 ... -
根据屏幕分辨率动态调整组件大小
2013-02-22 17:34 1557将代码写在组件的preInitialize事件监听器里面 简化 ... -
设置Flex组件的尺寸大小
2013-02-21 16:17 1577深红色部分标明了需注意的地方 另外要注意组件和容器的生命周 ... -
Flex minWidth minHeight
2013-02-04 16:17 1564minWidth 这个值并不是给组件自己用的,而是给组件的父容 ... -
ActionScript遍历绑定(BindProperty,BindSetter,ChangeWatcher)
2013-02-01 10:11 2501注意: 为防止内存益处,记得调用watcherInstance ... -
Flex程序适应不同屏幕尺寸和分辨率(滚动条)
2013-01-31 15:02 9870FlashBuilder编译后自动生成的xx.html里面定义 ... -
FlexContext, FlexClient,FlexSession
2013-01-15 15:05 2424使用了BlazeDS后,可以从FlexContext中获取一系 ... -
防止RemoteObject批处理AMF消息
2013-01-14 17:01 1319问题描述: 如果你在短时内调用同一个java对象上的两个方法, ... -
自动检测http和https的RemoteObject
2013-01-13 10:30 1821package { import util.Bro ... -
flex浏览器相关辅组类
2012-12-06 13:39 1284package util { import flash. ... -
Flex可变参数带来的问题
2012-12-06 13:34 1529当你在flex的方法中用了可变参数后,你会发现这些参数传到ja ... -
flexlib的treeGrid用法
2012-11-30 13:46 1327为了使用treeGrid,通常你需要定义自己的DataDesc ... -
自定义flex tree的DataDescriptor
2012-11-30 13:42 1445public class EnvironmentDataDes ... -
关于Boolean类型在flex与java中间传递的问题
2012-11-30 13:38 1287/** *为简化,只列举两个字段 */ publi ... -
给Flex的Tree赋值方式(XML和ArrayCollection)
2012-11-30 09:33 40611)方式一,mxml内嵌xml数据赋值方式,Embedded ... -
Custom Alert
2012-11-26 19:21 0<?xml version="1.0&qu ... -
Flex服务端分页
2012-11-14 17:00 1089Structure: model event ... -
Flex可携带数据的Aler组件(DataCarriableAlert)
2012-11-14 16:52 1368package component.alert { ... -
映射flex类到java内部类
2012-11-14 16:05 1210java端 public class Person{ p ...
相关推荐
在JavaScript中,`addMethod`函数通过`JavaScriptConnectFlex.addTo100()`来调用Flex中的`add`函数,`JavaScriptConnectFlex`是Flex应用程序的全局对象,`addTo100`是之前在Flex中注册的回调函数名。这使得...
2. 数据操作:创建实例后,你可以像操作普通对象一样,通过属性或方法来读写数据。例如: ```actionscript so.data.myProperty = "Some value"; ``` 3. 监听事件:为了追踪数据的变化,可以监听ShareObject的事件,...
3. **设置打印属性**:通过`PrintJob`对象的属性,如`jobName`、`showPrintOptions`等,可以定制打印作业的名称和是否显示打印选项对话框。 4. **启动打印**:调用`start()`方法启动打印作业。用户可以选择打印机、...
我们需要创建一个自定义的类来表示这些对象,包含必要的属性如ID、名称、位置等。 3. **实现GraphDataModel** - 创建一个GraphDataModel实例,它将作为流程图的数据源。在此模型中,我们添加节点和边的数据结构,...
从标签“Flex 3D 实例 例子”中我们可以推测,内容将专注于编程实践,包括3D场景的创建、3D对象的操纵、用户交互以及可能的数据绑定等。 根据压缩包内的文件名称列表,我们有以下组件: 1. **License.txt**:通常...
4. Flex组件:在提供的文件名称列表中,我们看到了如MyApp.mxml、Edit.mxml、Cart.mxml等文件,这些都是Flex应用中的组件或模块。MXML是Flex中用于构建用户界面的标记语言,类似于HTML。这些文件可能分别代表应用的...
确保在调用对象的方法或访问其属性之前,该对象已经被正确实例化。 2. Error 1046: Type was not found or was not a compile-time constant: className 这表示编译器无法找到指定的类名或该类在编译时未定义。检查...
通过RO服务,Flex应用可以与服务器端的业务逻辑进行交互,通常涉及AMF(Action Message Format)数据序列化,它允许高效地传输复杂的数据结构。 描述中提到的“flex和spring集成分页”是指将Flex客户端与Spring框架...
2. **加载XML数据**:在Flex应用中,我们可以使用`XML`类加载并解析XML文件。例如: ```actionscript var urlLoader:URLLoader = new URLLoader(); urlLoader.dataFormat = URLLoaderDataFormat.TEXT; urlLoader....
4. **使用自定义事件类**:在MXML文件中定义自定义事件,并在ActionScript代码中实例化该事件类的对象,设置数据后派发。 ```xml [Event(name="searchEvent", type="events.SearchEvent")] <![CDATA[ ...
FlexFactoryImpl 负责实例化 SpringFactoryInstance 并通过 SpringFactoryInstance 的 lookup() 方法查找 FlexService 接口对象: 清单 10. FlexFactoryImpl class public class FlexFactoryImpl implements...
但通过`SpringRemotingDestinationBootstrapService`,我们可以自动导出带有@Service注解且名称以“FlexService”结尾的Spring Bean,将其转换为BlazeDS的RemoteObject。 3. **配置属性**: `...
FlexFactoryImpl 负责实例化 SpringFactoryInstance 并通过 SpringFactoryInstance 的 lookup() 方法查找 FlexService 接口对象: 清单 10. FlexFactoryImpl class public class FlexFactoryImpl implements ...
1. **RemoteObject**:Flex中的RemoteObject类是用于远程调用服务器端服务的对象。它可以调用后端提供的服务,并接收返回的结果。 2. **AMFChannel**:AMFChannel是Flex中用于发送和接收数据的通道之一。它支持AMF...
创建一个新的ZIP文件,你可以通过实例化`ZipArchive`对象并调用其`addFile()`方法来添加文件。例如: ```actionscript var zip:ZipArchive = new ZipArchive(); zip.addFile("path/to/your/file", "entryName"); ``...
这个方法在组件的背景被绘制时调用,可以通过`Graphics`对象来绘制线条、形状等。例如: ```actionscript override protected function drawBackground(graphics:Graphics):void { graphics.beginFill(0xCCCCCC);...
在Flex中,事件的分发是通过继承自 `EventDispatcher` 类的对象的 `dispatchEvent` 方法来完成的。这个方法接受一个事件对象作为参数,并将其广播出去。其他监听该事件的组件可以通过事件的名称来判断是否接收这个...
1. 实例化RemoteObject:`service = new RemoteObject("helloService");` 这里"helloService"是服务的标识,对应Java端的服务接口或类。 2. 设置请求超时时间:`service.requestTimeout = 600;` 这意味着如果在10...
- **实例化**:创建`FileReference`对象。 - **browse() 方法**:弹出文件选择对话框。 - **upload() 方法**:上传文件到服务器。 #### 2.2 FileReferenceList - **实例化**:创建`FileReferenceList`对象。 - **...