---
title: "用Mate实现Flex组件间交互--ListenerInjector"
author: "lectery"
date: "2010-04-28T16:52:55Z"
tags: []
categories: ["Web前端"]
slug: "mate-flex-listenerinjector"
draft: false
lastmod: "2010-04-28T16:53:30Z"
id: 655398
url: "https://lectery.iteye.com/blog/655398"
---

Mate的ListenerInjector实现的视图中的监听器动态注入，可以在EventMap中动态定义视图层的监听器。简单的使用方法如下：

1. 在EventMap中添加如下定义
   
   ```
   <Injectors target="{MyTarget}">
   	<ListenerInjector eventType="{MyEvent.SELECT_ITEM}" method="doHandle"  />
   </Injectors>
   ```
2. 在MyTarget.mxml中定义public的doHandle方法，该方法必须有一个事件类型的参数
   
   ```
   public function doHandle(event:Event):void{
   				Alert.show('hehe');
   			}
   ```

 

一点资料：

- [Mate的ListenerInjector](http://waterxbread.blogspot.com/2009/12/matelistenerinjector.html)
- [Mate Documentation](http://mate.asfusion.com/page/documentation/tags/listenerinjector)