Flex 개발 입문
6808 단어 Flex
Flex 프로 그래 밍 기초
대상 지향 프로 그래 밍
위의 Hello World 의 예 에서 우 리 는 HTML 에 JavaScript 를 삽입 한 것 처럼 mxml 에 Action Script 코드 를 삽입 하여 업무 논 리 를 실현 할 수 있 음 을 알 수 있다.맞다!Flex 에서 mxml 와 Action Script 의 관 계 를 Html 과 JavaScript 의 관계 로 이해 하면 Flex 에 대해 이렇게 잘 알 게 될 것 입 니 다!
Action Script 언어 는 대상 을 대상 으로 하 는 스 크 립 트 언어 로 작성 방식 도 JavaScript 와 매우 비슷 합 니 다.mxml 에 끼 워 넣 을 수 있 는 것 외 에 자바 스 크 립 트 가 단독. 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 Event
metadata tag, the ManagedEvents
metadata tag, and EventDispatcher#dispatchEvent
. Of these three, only ManagedEvents
is a Parsley-specific addition. The Event
metadata is just good practice, and dispatchEvent
is required to do the work. Parsleywill use ManagedEvents
to 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 InjectConstructor
instructs Parsleyto inject a declared object of type User
into the constructor of DashboardPM. For setter injection you just need to add the
Inject
metadata 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
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
⭐️ Flex & OpacityThe flex CSS shorthand property sets how a flex item will grow or shrink to fit the space available in its flex containe...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.