0
votes

I have a List with TextInput as item renderer. I want to get the value entered in the TextInput (form the TextInputItemRenderer) and pass it the main application to do some checks(upon tapping enter on the textInput -- see code below).

I know that we can do it thru dispatching event but I still don't understand how to pass a variable from the ItemRenderer to the main app.

Help Pls.

Thanks

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                xmlns:mx="library://ns.adobe.com/flex/mx" 
                autoDrawBackground="true" xmlns:components="components.*" width="100%"
                >

    <s:layout> 
        <s:HorizontalLayout/> 
    </s:layout> 

    <fx:Script>
        <![CDATA[


            override public function set data( value:Object ) : void {
                super.data = value;
            }

            protected function myTextInput_enterHandler(event:FlexEvent):void
            {

                trace(myTextInput.text);
                                What Next??


            }


        ]]>
    </fx:Script>

    <components:ClearableTextInput text="{data.label}" id="myTextInput" enter="myTextInput_enterHandler(event)"/>

</s:ItemRenderer>
2

2 Answers

0
votes

i'm not sure if I got your question correctly but would this help?

http://www.ajibanda.blogspot.com/2011/02/changing-currentstate-of-main-and.html

0
votes

Instead of trying to access from MainApp to itemRenderer, i think you can do backward. Follow one of two solutions below:

  1. In itemRenderer, assign value you want to check later to a public global variable on the MainApp. The limitation is you then only enable to check it on MainApp, not any where esle (other itemRenderer, component, module etc.)

  2. Use EvenBus to put the value to a global container. Create a static eventBus instance in AppUtils, for example. In itemRenderer, AppUtils.eventBus.dispatch() an event with the value attached to it each time the value changed. And then use AppUtils.eventBus again to addEventListener() to retrieve the value and check wherever you want. Google AS3Commons for EventBus.