flashapache-flexactionscript-3stringtilelist

How do I know which characters in a string allocated?


I have an application that replaces the selected text in the row for the selected symbol from tilelist, which are loaded dynamically characters! I do not know how to do that would be able to determine how many characters are selected, if you select a symbol, then download certain characters (replace) and if other then the other characters, if characters are not selected as or selected as tsyfry ... then the message ...

I made ​​just to highlight character is replaced by selected from tilelist ... How do the rest! please help ....

<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    applicationComplete="contactsService.send()"
    creationComplete="init()" 
    layout="absolute" viewSourceURL="srcview/index.html">
    <fx:Script>
        <![CDATA[

            private function replaceSelect(event:MouseEvent):void
            {
                var obj:Object = lst.selectedItem;
                var selStr:int = txt.selectionBeginIndex;
                var selEnd:int = txt.selectionEndIndex;

                if((lst.selectedItem != null)&&(selStr!=selEnd))
                {
                    txt.text = txt.text.substring(0,selStr)+lst.selectedItem.toString()+txt.text.substring(selEnd,txt.text.length)
                }
                lst.visible = false;
            }           

            [Bindable]
            private var cm:ContextMenu;

            private function init():void {
                var cmi:ContextMenuItem = new ContextMenuItem("Special Characters", true);
                cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, cmSelect);
                cm = new ContextMenu();
                cm.hideBuiltInItems();
                cm.customItems = [cmi];

            }

            private function cmSelect(evt:ContextMenuEvent):void {
                lst.visible = true;

            }

        ]]>
    </fx:Script>
    <fx:Declarations>
        <mx:HTTPService id="contactsService"
                        resultFormat="e4x"
                        url="symbols.xml"/>
    </fx:Declarations>
    <mx:Panel width="508" height="487" x="20" y="20">
        <mx:TextInput 
            id="txt" 
            text="Test String Flex" 
            contextMenu="{cm}" 
            width="303"/>
        <mx:TileList 
            id="lst" 
            visible="false" 
            dataProvider="{contactsService.lastResult.symb}" 
            columnCount="4"
            columnWidth="25"
            rowCount="3"
            rowHeight="25"
            verticalScrollPolicy="on"
            click="{replaceSelect(event)}"/>
    </mx:Panel>
</mx:Application>

Solution

  • To get user selected STRING you can get it Like this

    var userSelectedText:String  = txt.text.substring(selStr, selEnd);
    

    and user selected Symbol can be get as

    var userSelectedSymbol:String = lst.selectedItem.toString();
    

    and you can use array to maintain repalce history as

    Declare Array at class level

    var repalceHistory :Array = ne Array();
    

    and Save user action as

    var action:Object = new Object();
    action.symbol = userSelectedSymbol;
    action.selectedText = userSelectedText;
    
    repalceHistory.push(action);
    

    and can get History as

    var action:Object = repalceHistory.pop();
    

    Hopes that helps