0

我有一个应用程序可以替换 tilelist 中所选符号的行中所选文本,这些符号是动态加载的字符!我不知道该怎么做才能确定选择了多少个字符,如果您选择一个符号,则下载某些字符(替换),如果不是其他字符,则如果字符未被选为或选为 tsyfry ...然后消息...

我只是为了突出显示字符被替换为从tilelist中选择...其余的怎么办!请帮忙 ....

<?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>
4

1 回答 1

0

要让用户选择 STRING,您可以像这样获得它

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

用户选择的符号可以作为

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

并且您可以使用数组来维护替换历史记录为

在类级别声明数组

var repalceHistory :Array = ne Array();

并将用户操作另存为

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

repalceHistory.push(action);

并且可以将历史记录为

var action:Object = repalceHistory.pop();

希望有帮助

于 2011-04-20T11:47:28.107 回答