0

動的に文字がロードされるタイルリストから選択されたシンボルの行で選択されたテキストを置き換えるアプリケーションがあります!シンボルを選択してから特定の文字をダウンロード(置換)し、それ以外の場合は他の文字をダウンロードして、文字がtsyfryとして選択されていないか、選択されていない場合は、選択されている文字数を判別できる方法がわかりません。 ...次にメッセージ..。

キャラクターをハイライトするためだけに、タイルリストから選択したものに置き換えて作成しました...残りはどうですか?助けてください ....

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

ユーザーが選択した文字列を取得するには、次のように取得できます

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

ユーザーが選択したシンボルは次のように取得できます

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

配列を使用して、repalce履歴を次のように維持できます。

クラスレベルで配列を宣言する

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 に答える