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

Event handlers in Repeater components

    博客分类:
  • flex
阅读更多
<?xml version="1.0"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script> 
        <![CDATA[
             public function clicker(cName:String):void { 
                  foolabel.text=cName; 
             }    
        ]]>
    </mx:Script> 

    <mx:Label id="foolabel" text="foo"></mx:Label> 
 
    <mx:Model id="data"> 
        <color>
            <colorName>Red</colorName> 
            <colorName>Yellow</colorName> 
            <colorName>Blue</colorName>
        </color>
    </mx:Model> 
    <mx:ArrayCollection id="myAC" source="{data.colorName}"/>

    <mx:Repeater id="myrep" dataProvider="{myAC}"> 
        <mx:Button click="clicker(event.currentTarget.getRepeaterItem());"
            label="{myrep.currentItem}"/> 
    </mx:Repeater> 
</mx:Application>

After the user clicks the Yellow button, the application looks like this:


The code in the following example uses the getRepeaterItem() method to display a specific URL for each Button control that the user clicks. The Button controls must share a common data-driven click handler, because you cannot use binding expressions inside event handlers. However, the getRepeaterItem() method lets you change the functionality for each Button control.

<?xml version="1.0"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[
            [Bindable]
            public var dp:Array = [ { label: "Flex",
                url: "http://www.adobe.com/flex" },
                { label: "Flash", url: "http://www.adobe.com/flash" } ];
        ]]>
    </mx:Script>

    <mx:ArrayCollection id="myAC" source="{dp}"/>
    <mx:Repeater id="r" dataProvider="{myAC}">
        <mx:Button label="{r.currentItem.label}" click="navigateToURL(new
            URLRequest(event.currentTarget.getRepeaterItem().url));"/>
    </mx:Repeater>
</mx:Application>

When executed, this example yields two buttons: one for Flex and one for Flash. When you click the button of your choice, the relevant product page loads in a new browser window.


<script type="text/javascript"></script>

分享到:
评论

相关推荐

    (转)Developer's Guide - Event Handlers

    【标题】"Developer's Guide - Event Handlers" 是一篇关于开发者如何在编程中处理事件的指南。这个主题在软件开发,尤其是交互式应用开发中至关重要,因为它涉及到用户与应用程序的交互方式。事件处理器是程序响应...

    Web event handlers

    总结了IE 5 ,页面的所有事件 Dom Event Handlers/Dom 事件处理函数

    Javascript Event Handlers.zip

    JavaScript事件处理器是JavaScript编程中的核心概念,用于处理用户与网页之间的交互。...理解并熟练掌握JavaScript事件处理机制对于创建动态和交互性强的网页至关重要。 事件是浏览器或JavaScript引擎在特定时刻触发的...

    Disruptor3.x Disruptor使用方式

    EventHandler&lt;Event&gt;[] eventHandlers=new DisruptorEventHandler[]{new DisruptorEventHandler()}; DisruptorPublisher dp=new DisruptorPublisher(1024, eventHandlers); dp.start(); for (int i = 0; true;...

    Eclipse下的可视化界面设计WindowBuilder插件所有版本打包

    Event Handling – add event handlers to your components. Menu Editing – visually create and edit menubars, menu items and popup menus. Morphing – convert one component type into another.

    Rx.NET in Action

    on with in-depth code examples to discover firsthand how to exploit the rich query capabilities that Rx provides and the Rx concurrency model that allows you to control both the asynchronicity of your...

    C#版本EventBus事件总线实例源码

    foreach (var handler in _eventHandlers[eventType]) { ((Action)handler)(@event); } } } } // 使用示例 public class UserCreatedEvent : IEvent { public string UserName { get; set; } } public ...

    C#版本EventBus事件总线实例源码_(0601).rar

    foreach (var handler in _eventHandlers[eventType]) { ((Action)handler)(args); } } } } ``` 在这个实现中,`EventBus`类维护了一个字典 `_eventHandlers`,用于存储不同类型的事件及其对应的处理方法。`...

    C#版本EventBus事件总线实例源码_0520.rar

    foreach (var handler in _eventHandlers[eventType]) { ((Action)handler)(eventData); } } } } ``` 在这个例子中,`EventBus` 类维护了一个事件处理器的字典,其中键是事件类型,值是对应的处理函数列表。`...

    C#版本EventBus事件总线实例源码.rar

    foreach (var handler in _eventHandlers[eventType]) { ((EventHandler)handler)(sender, args); } } } } ``` 5. **使用示例**:在实际应用中,发布者触发事件,事件总线负责分发,订阅者接收到事件并进行...

    C#版本EventBus事件总线实例源码_14.rar

    foreach (var handler in handlers) { ((Action)handler)(args); } } } } ``` 在这个类中,`Subscribe`方法用于订阅事件,`Unsubscribe`方法用于取消订阅,`Publish`方法用于发布事件。`TEvent`是泛型类型,...

    Event Bus C# 事件总线

    foreach (var handler in eventHandlers) { ((Action)handler)(@event); } } } } ``` 现在,你可以创建事件发布者和订阅者。发布者只需调用`EventBus.Publish`来发送事件,而订阅者通过`EventBus.Subscribe`...

    C#版本EventBus事件总线实例源码--值得下载

    foreach (var handler in handlers) { ((Action)handler)(@event); } } } } } ``` 在实际应用中,我们可以在不同的类或组件中订阅和发布事件。例如,一个业务组件可以发布`MyCustomEvent`,而UI或其他组件...

    flexpaper_handlers.js

    《Flexpaper Handlers.js详解》 Flexpaper Handlers.js是Flexpaper文档查看器中的核心脚本文件,主要用于处理用户交互和各种事件。在深入探讨这个文件之前,我们先了解一下Flexpaper是什么。Flexpaper是一款强大的...

    Data-Access---Custom-Data-Binding-Format-Handlers_back

    This application demonstrates how to use the Format and Parse event handlers when data binding Windows Form controls. The Format event fires when the data is transferred the data source to the bound ...

    Reactive Programming in Kotlin PDF

    You will dive into advanced techniques such as manipulating time in data-flow, customizing operators and provider and how to Use the concurrency model to control asynchronicity of code and process ...

    handlers.js

    handlers.js

    HTML DOM Event 对象

    事件句柄(Event Handlers)是HTML 4.0引入的新特性,允许我们通过在HTML标签中添加特定属性来指定事件发生时的行为。例如,`onclick`属性会在用户点击元素时调用关联的JavaScript函数。以下是一些常见的事件句柄: ...

Global site tag (gtag.js) - Google Analytics