`
oywl2008
  • 浏览: 1050993 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Flex 开发入门

 
阅读更多

http://www.ibm.com/developerworks/cn/web/wa-lo-flexdev/

 

Flex 编程基础

面向对象的编程

在上面 Hello World 的例子中我们可以看出,就像在 HTML 中嵌入 JavaScript 那样,我们可以在 mxml 里面嵌入 Action Script 代码来实现业务逻辑。没错!如果您把 Flex 中 mxml 和 Action Script 的关系理解为 Html 和 JavaScript 的关系,您会忽然发现您对 Flex 变的如此熟悉!

Action Script 语言是面向对象的脚本语言,它连编写方式都和 JavaScript 非常的相似。除了可以嵌套在 mxml 里面之外,它还可以像 JavaScript 写在单独的 .js 文件里面那样写在单独的 .as 文件里面,然后在 mxml 里面引入它。

 

 

Parsley

Framework: Parsley

Website: http://www.spicefactory.org/

Developer: Jens Halm

Version: 2.0.0

License: Open source

Configuration: XML/MXML/ActionScript

Parsley is another mature IOC framework that was originally inspired by Spring. It has recently undergone a major rewrite. The new version employs native Flex features like binding and metadata to give you greater options for configuring your project.

Core concepts

Central to Parsley is the idea of a context. This comes from Spring and refers to the dependency injection configuration for the application.

Configuration in Parsley is now available in a variety of options, including XML and MXML. You can use native MXML markup or custom MXML tags from the Parsley library. To enable the injection mechanism, Parsley uses metadata tags, similar to the Swiz framework.

Parsley comes with messaging patterns too. With very little intrusive code, you can enable your objects as event sources or event handlers. I used this capability in this example instead of using the Controller pattern.

Basic Parsley configuration

There are three basic steps to Parsley configuration:

Create a Config.mxml file

Initialize a Context in the root of the application

Add the Inject metadata to the dependencies in your views.

Although there are other options as to how you prepare your configuration file, for this example I'm using an MXML file with native markup and Parsley tags. This approach has the benefit of including classes at compile time at the expense of not being able to update the configuration of an already compiled application.

Object factory and object configuration

In the Config.mxml you will see all the application objects, from domain models to delegates. They are declared in two ways:

In standard MXML

Using Parsley's object definition tags

I will go into more detail of these two types in a later section.

Setting up the controller (and LoginHandler)

Instead of using my hand-rolled controller, I have used Parsley's messaging system, which is designed to have a minimal impact on the objects that you write. It makes use of metadata to do this. An object that is visible to the Context and has this metadata will allow Parsley to wire up the event source to the event handler.

In the example application, LoginPM is the event source, and LoginAction (which I've renamed from LoginHandler) is the event handler.

Here is an excerpt from LoginPM:

[Event( name="LOGIN", type="com.adobe.login.control.event.LoginEvent")] [ManagedEvents("LOGIN")] public class LoginPM extends EventDispatcher { ... public function login() : void { var event : LoginEvent = new LoginEvent( username, password ); dispatchEvent( event ); } }

The three items that enable this as an event source are the Eventmetadata tag, the ManagedEventsmetadata tag, and EventDispatcher#dispatchEvent. Of these three, only ManagedEventsis a Parsley-specific addition. The Event metadata is just good practice, and dispatchEventis required to do the work. Parsleywill use ManagedEventsto determine which events it needs to handle and delegate to event handlers.

 

Here is an excerpt from LoginAction, which has been configured as an event handler:

public class LoginAction implements IResponder { [MessageHandler] public function execute( event : LoginEvent ) : void { ... } }

Because I added MessageHandler metadata to this function, Parsley will add this object/function as a listener to any event of type LoginEvent.

To make these objects visible to Parsley, I can declare the object within the configuration file that I pass into FlexContextBuilder or I can use the Configure object in my views.

Injecting the presentation models

As with all the examples, I’ve made the presentation models nonhierarchical. See the explanation in the Spring ActionScript section for more information.

Parsley supports both setter injection and constructor injection. As I noted with the Spring ActionScript example, I prefer constructor injection because it exposes the dependencies that the object needs to function. Below is the configuration for DashboardPM:

<spicefactory:Object type="{ DashboardPM }"/>

If your object requires constructor arguments, you’ll want to declare it using an Object tag because such arguments are not supported in native MXML.

To complete the constructor, you add some metadata to your class:

[InjectConstructor] public class DashboardPM { public var user : User; public function DashboardPM( user : User ) { this.user = user; } ... }

The metadata tag InjectConstructorinstructs Parsleyto inject a declared object of type Userinto the constructor of DashboardPM.

For setter injection you just need to add the Injectmetadata tag to your classes. For example, I declare SummaryPM in standard MXML inside Config:

<dashboard:SummaryPM/>

In the class file, I then have:

public class SummaryPM { [Inject] public var friends : Friends; ... }

The Inject tag indicates that an instance of type Friends needs to be injected into this instance.

Parsley summary

Inspired by some of the innovations that the other frameworks have pioneered, the new version of Parsley is a complete IOC framework. It also supports modular development to support unloading of contexts. This is an important feature for a growing number of Flex applications that make use of modules.

http://www.adobe.com/devnet/flex/flex_java.html

 

 

 

分享到:
评论

相关推荐

    Flex开发入门

    总结一下,Flex开发入门涉及MXML文件的创建、UI组件的使用,以及与J2EE项目的交互。通过学习这些基础知识,开发者可以开始构建功能丰富的富互联网应用程序。压缩包内的`Flex 开发入门.mht`可能是一个教程文档,包含...

    flex开发入门 actionscript

    ### Flex开发入门与ActionScript详解 #### 一、Flex与ActionScript简介 Flex是一种用于构建高性能的、跨浏览器的Web应用程序的开源框架。它由Adobe Systems维护和支持,并且以其强大的功能和灵活性受到开发者们的...

    Flex开发入门指南

    Flex开发入门指南

    Java与Flex开发入门

    **Java与Flex开发入门** Java和Flex是两种广泛用于创建丰富互联网应用程序(RIA,Rich Internet Applications)的技术。本文将深入探讨这两个技术平台的基础知识,以及它们如何协同工作以提供卓越的用户体验。 ...

    【转帖】Flex 开发入门

    Flex开发入门是一个面向初学者的主题,它涉及到Adobe Flex这一开源框架的使用,用于构建富互联网应用程序(RIA)。Flex是基于ActionScript和MXML,这两种语言允许开发者创建具有交互性、动态性和高性能的Web应用程序...

    Flex开发入门PDF电子书

    ### Flex开发入门知识点详解 #### 一、Flex简介与特性 **Flex** 是一款由Adobe推出的开源框架,主要用于构建高质量的Rich Internet Applications (RIA),即富互联网应用。它结合了强大的编程语言(ActionScript)...

    arcgis api for flex 开发入门

    《ArcGIS API for Flex开发入门详解》 ArcGIS API for Flex是Esri公司推出的一款用于构建富互联网应用程序(RIAs)的开发库,它作为ArcGIS Server 9.3的一部分,旨在提供更快的运行速度和更好的用户体验,尤其在...

    FLEX开发入门

    标题中的"FLEX开发入门"指的是学习Adobe Flex框架的初级阶段,Flex是一种用于构建富互联网应用程序(RIA)的开源开发工具,主要使用ActionScript语言和MXML进行编程。它允许开发者创建交互性强、功能丰富的Web应用,...

    arcgis api for flex 开发入门(三)地图浏览控件的使用

    arcgis api for flex 开发入门(三)地图浏览控件的使用

    arcgis api for flex 开发入门(二)Map的创建

    arcgis api for flex 开发入门(二)Map的创建

    arcgis api for flex 开发入门(五)查询

    arcgis api for flex 开发入门(五)查询

    flex开发入门资料

    Flex开发是一种创建富互联网应用程序(RIA)的技术,它基于Adobe Flash Platform,主要使用ActionScript编程语言。本套入门资料专为初学者设计,旨在帮助学习者掌握Flex的基础知识和技能,从而能够构建交互性强、...

    arcgis api for flex 开发入门(一)环境搭建

    arcgis api for flex的环境搭建

    java整合flex开发应用

    1. **环境配置**:如何设置Java开发环境(JDK、IDE)和Flex开发环境(Flex SDK、IDE),以及如何配置BlazeDS或LCDS等数据通信工具。 2. **数据交互**:使用AMF(Action Message Format)协议进行Java和Flex之间的...

    Flex从入门到精通源代码

    8. **应用程序结构**:讲解MVC(模型-视图-控制器)或其他设计模式在Flex开发中的应用,帮助组织和管理代码。 9. **高级主题**:可能包括自定义组件开发、性能优化、错误处理和调试技巧等进阶内容。 压缩包中的`...

    Flash+Flex+Air移动开发入门经典 pdf

    《flash+flex+air移动开发入门经典——适用于android、ios和blackberry》 第1章 flash、flex和air简介 1 1.1 adobe flash 1 1.2 actionscript 3.0 2 1.2.1 ecmascript 2 1.2.2 关键概念 3 1.3 flex框架 11 ...

Global site tag (gtag.js) - Google Analytics