简体   繁体   中英

Binding custom components values

I have built a custom component using some containers and a TileList. Now when I instantiate that component in my main Flex app, I want to get the value of the selected item in the tileList that the user clicks on. In other words, everytime the user clicks an item in the tileList, I want it to assign that selected value to a global application variable in the main flex app. Any ideas how to do that?

Below is one way that you can listen to the change of TileList.selectedItem. I would recommend against putting this in a global variable, although if you must you could use a pattern like ModelLocator to do so.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical">

    <mx:Script>
        <![CDATA[

            [Bindable] public var selectedItem:Object;

        ]]>
    </mx:Script>

    <mx:Binding source="listTile.selectedItem" destination="selectedItem"/> 

    <mx:Label text="{ selectedItem }"/>

    <mx:TileList
        id="listTile"
        width="400"
        height="300"
        dataProvider="{ ['A','B','C'] }"/>

</mx:Application>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM