【问题标题】:AS3 Jump To Certain Word In Multiline Textfield?AS3 跳转到多行文本字段中的某个单词?
【发布时间】:2011-11-10 20:07:33
【问题描述】:

我想在多行的文本文件中搜索一个单词,发现这没什么大不了的,但我可以滚动到那个位置,就像记事本一样,当你点击下一个查找时它会跳转到那个点

我不是要求为我做这件事,你能给我一个提示我应该去哪里看吗?

提前致谢

编辑解决方案

var textInput:String="String To Search";
txt.text=textInput; // txt is a dynamic textfield

var currentIndex:int = 0;

function search(searchInput) {

    var searchString:String = searchInput.toLowerCase();
    txt.stage.focus = txt;
    var txtForSearch:String = textInput.toLowerCase();

    if(currentIndex == 0){
        var index:int = txtForSearch.indexOf(searchString,currentIndex);
        currentIndex  = index+searchString.length;
    } else {
        index = txtForSearch.indexOf(searchString,currentIndex);
        currentIndex  = index+searchString.length;
    }
    if(index < 0) {
        txt.setSelection(0, 0);
    } else {
        txt.setSelection(index, currentIndex);
    }
}

input.addEventListener(TextEvent.TEXT_INPUT, inputChanged);
function inputChanged (e:TextEvent):void {
    currentIndex = 0;
}

srBtn.addEventListener(MouseEvent.CLICK,doSearch) // srBtn my search button instance
function doSearch(e:Event):void{
    search(input.text); // input is an input textfield ( search query )     
};

【问题讨论】:

    标签: flash actionscript-3 flash-builder


    【解决方案1】:

    【讨论】:

    • TextField.getCharBoundaries() 在 texfield 的可见部分返回某个索引,我的意思是如果文本太长 getCharBoundaries() 如果给定的索引未显示在 textfield 的可见部分,则返回 null !有什么解决办法吗?
    • 也许是while(!tf.getCharBoundaries(1111)){tf.scrollV++;}
    • 我用 setSelection 做到了,无论如何谢谢你,你的建议让我在论坛上发表了不错的帖子
    【解决方案2】:

    我为这个问题苦苦挣扎了好几个小时。我得到一个空矩形,我最终发现文本字段的原始大小小于自动调整大小以适应更多文本后的扩展大小。

    原始 textField 大小之外的所有内容都返回 null。我通过扩大舞台上 textField 的大小解决了这个问题,使其足以容纳所有动态文本。

    我通常不使用时间轴动画,但它是客户提供的文件。

    感谢这个循环帮助我弄清楚发生了什么:

    for(var i:int= 0; i<tf.text.length; i++)
    {
    var char:String = tf.text.substr(i,1);
    trace(i, ": " , (char=="\n"||char=="\r" ?"<CR>":char) ,": ",  tf.getCharBoundaries(i))
    }
    

    【讨论】:

      猜你喜欢
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-03
      相关资源
      最近更新 更多