在手机上自动完成 - AS3

时间:2015-05-28 00:54:55

标签: ios actionscript-3 flash autocomplete

我已经制作了一个在swf文件中运行良好的自动完成功能。

enter image description here

非常简单,当用户写第一个字母时,建议用文字。

我已经发布了IOS的项目。 当我在Iphone 上尝试时,在输入第一个字母时没有任何建议。 我必须写第一个字母,然后点击“输入”以显示建议...

我不希望用户“验证”以获得建议,只需输入一封信即可。

你知道可能是什么问题吗?有人可以帮帮我吗? 很奇怪,我尝试使用Android设备它的效果非常好! (比如我的瑞士法郎)。

这是我的代码:

urlLoader.load(new URLRequest("test.txt"));
            urlLoader.addEventListener(Event.COMPLETE, loadComplete);
            inputField.addEventListener(KeyboardEvent.KEY_UP, suggest);

 function loadComplete(e:Event):void
        {
            suggestions = e.target.data.split(",");
        }

         function suggest(e:KeyboardEvent):void
        {
            suggested = [];

            for (var i:int = 0; i < textfields.length; i++)
            {
                removeChild(textfields[i]);
            }

            textfields = [];

            for (var j:int = 0; j < suggestions.length; j++)
            {
                if (suggestions[j].indexOf(inputField.text.toLowerCase()) == 0)
                {
                    var term:TextField = new TextField();
                    term.width = 300;
                    term.height = 20;
                    term.x = 70;
                    term.y = (20 * suggested.length) + 314;
                    term.border = true;
                    term.borderColor = 0x353535;
                    term.background = true;
                    term.backgroundColor = 0xFF9900;
                    term.textColor = 0x4C311D;
                    term.defaultTextFormat = format;

                    term.addEventListener(MouseEvent.MOUSE_UP, useWord);
                    term.addEventListener(MouseEvent.MOUSE_OVER, hover);
                    term.addEventListener(MouseEvent.MOUSE_OUT, out);
                    term.addEventListener(MouseEvent.CLICK, tellMe);

                    addChild(term);
                    textfields.push(term);

                    suggested.push(suggestions[j]);

                    term.text = suggestions[j];
                }

            }

            if (inputField.length == 0)
            {
                suggested = [];

                for (var k:int = 0; k < textfields.length; k++)
                {
                    removeChild(textfields[k]);
                }

                textfields = [];
            }

            if(e.keyCode == Keyboard.DOWN && currentSelection < textfields.length-1)
            {
                currentSelection++;
                textfields[currentSelection].textColor = 0x4C311D;
            }

            if(e.keyCode == Keyboard.UP && currentSelection > 0)
            {
                currentSelection--;
                textfields[currentSelection].textColor = 0x4C311D;
            }

            if(e.keyCode == Keyboard.ENTER)
            {
                inputField.text = textfields[currentSelection].text;

                suggested = [];

                for (var l:int = 0; l < textfields.length; l++)
                {
                    removeChild(textfields[l]);
                }

                textfields = [];
                currentSelection = 0;
            }
        }

         function useWord(e:MouseEvent):void
        {
            inputField.text = e.target.text;

            suggested = [];

            for (var i:int = 0; i < textfields.length; i++)
            {
                removeChild(textfields[i]);
            }

            textfields = [];
        } 

谢谢

修改

这是我使用Stagetext的新代码

var myTextField:StageText = new StageText();
         var stageTextInitOptions:StageTextInitOptions;
         var urlLoader:URLLoader = new URLLoader();
         var suggestions:Array = new Array();
         var suggested:Array = new Array();
         var textfields:Array = new Array();
         var format:TextFormat = new TextFormat();
         var currentSelection:int = -1;
         var searchChannel:SoundChannel = new SoundChannel();


            myTextField.returnKeyLabel = ReturnKeyLabel.SEARCH;
            myTextField.addEventListener(KeyboardEvent.KEY_UP, suggest);
            stageTextInitOptions = new StageTextInitOptions(false);
            myTextField = new StageText(stageTextInitOptions);
            myTextField.softKeyboardType = SoftKeyboardType.DEFAULT;
            myTextField.returnKeyLabel = ReturnKeyLabel.DONE;
            myTextField.autoCorrect = true;
            myTextField.fontSize = 20;
            myTextField.color = 0x000000;
            myTextField.fontWeight = "bold";
            myTextField.stage = this.stage;
            myTextField.viewPort = new Rectangle(25, 108, stage.stageWidth-40, 28);



            urlLoader.load(new URLRequest("Sports2.txt"));
            urlLoader.addEventListener(Event.COMPLETE, loadComplete);
            myTextField.addEventListener(KeyboardEvent.KEY_UP, suggest);

1 个答案:

答案 0 :(得分:0)

KeyboardEvent.KEY_UP,KeyboardEvent.KEY_DOWN,TextEvent.TEXT_INPUT在iOS上不起作用。 KeyboardEvent.KEY_DOWN仅在某些键上调度。我只看到了键“Enter”。