0
votes

I have a TextInput inside a spark Item Renderer. I need to undo some behavior in a library I'm using by stopPropagation of the mouseDown and mouseUp event for the TextInput. However, I would like the TextInput itself to handle such events normally - otherwise the caret to cursor transitions don't seem to be properly handled. I'm ashamed to admit, I'm not sure how to do this - seems simple but I have been stuck on it for some time.

thank you!


Edit: ok, here's some code to explain what's going on (although it's completely unrelated from what I'm doing, so it's not an exact depiction of my specific situation). As I mentioned above I need to be able to stop the propagation of mouseDown and mouseUp from the TextInput to a component up the food chain - event.stopPropagation() in mouseDown and mouseUp for the TextInput does the trick. However, it messes up the caret / cursor handling for the TextInput itself. Try the code below with or without the event.stopPropagation() and you should see what I mean.

Main

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/03/19/using-a-custom-item-renderer-function-with-the-fxlist-control-in-flex-gumbo/ -->
<s:Application name="Spark_List_itemRendererFunction_test"
               xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Script>
        <![CDATA[
            import mx.core.ClassFactory;
            import spark.skins.spark.DefaultItemRenderer;

            private function list_itemRendererFunc(item:Object):ClassFactory {
                var cla:Class = DefaultItemRenderer;
                switch (item.type) {
                    case "employee":
                    case "manager":
                        cla = EmployeeItemRenderer;
                        break;
                    default:
                        break;
                }
                return new ClassFactory(cla);
            }
        ]]>
    </fx:Script>

    <s:List id="list"
            labelField="name"
            itemRendererFunction="list_itemRendererFunc"
            horizontalCenter="0" verticalCenter="0">
        <s:dataProvider>
            <s:ArrayList>
                <fx:Object name="Employee 1" type="employee" />
                <fx:Object name="Employee 2" type="employee" />
                <fx:Object name="Employee 3" type="employee" />
                <fx:Object name="Employee 4" type="employee" />
                <fx:Object name="Manager 1" type="manager" />
                <fx:Object name="Manager 2" type="manager" />
                <fx:Object name="Employee 5" type="employee" />
                <fx:Object name="Manager 3" type="manager" />
                <fx:Object name="Consultant 1" type="consultant" />
            </s:ArrayList>
        </s:dataProvider>
    </s:List>

</s:Application>

and EmployeeItemRenderer.mxml

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/03/19/using-a-custom-item-renderer-function-with-the-fxlist-control-in-flex-gumbo/ -->
<s:ItemRenderer name="EmployeeItemRenderer"
                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">

    <fx:Script>
        <![CDATA[
            protected function TI_mouseDownHandler(event:MouseEvent):void
            {
                event.stopPropagation();
            }

            protected function TI_mouseUpHandler(event:MouseEvent):void
            {
                event.stopPropagation();
            }

        ]]>
    </fx:Script>


    <s:HGroup>
        <s:Label id="labelDisplay" left="4" right="4" top="4" bottom="4" />
        <s:TextInput id="TI" mouseDown="TI_mouseDownHandler(event)" mouseUp="TI_mouseUpHandler(event)"/>
    </s:HGroup>

</s:ItemRenderer>
2
provide some code. We can't deem it simple or hard if you don't show us what you want.J_A_X
JAX, as mentioned below this is one of those cases where it's hard to extract code from the project. Will try to fabricate something and post it though - I'm aware that having code makes things simpler...fred august
ok, posted code. Thank you for your help!fred august
It's working fine for me. Tried with Flex 4.1 and 4.5 on Windows 7 machine. You on a mac?J_A_X
Windows 7, Flex 4.01. Are there major risks in moving to 4.1 or 4.5 as far as breaking things?fred august

2 Answers

0
votes

Can you post what you've tried so far?

I think all you would need to do is register listeners for the mouseDown, mouseUp, and click events and then use http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html#stopPropagation() to stop the events from bubbling further from the currentTarget out to the parents, stopImmediatePropagation would stop the event from triggering listeners on the current object.

Shaun

PS I'll edit if you post some code and I can clarify.

0
votes

OK, Sounds like this is only an issue for Flex 4.01 (thank you JAX). In such case I got what I wanted by stopping propagation on the mousedown event but not on the mouseUp. This is a very specific case that applies to my code, so I'm not sure if it'll be really useful for anyone else. I guess the interesting lesson for me, here, is that mouseUp is the event that is related to caret / system cursor management.