Просмотр полной версии : Изменение Text-ового поля
Здр.
Предположим, существует файл some.fla
вот:
http://www.flasher.ru/forum/attachment.php?attachmentid=22564&stc=1&d=1247546709
1. Text Input (all text)
2. Text Input (www.something.com)
3. Button (send) <a href=""></a>
Как сделать, чтобы при нажатии на Button(3),
ссылка из text-ового поля(2),
добавлялась в text-ового поле(1) с тегом <a href=""></a>
Жду ответа
С ув. l576
пр.
var app: Object = this;
var outputTextField: TextField;
var inputTextField: TextField;
this.button.onRelease = function():Void {
app.outputTextField.text = '<a href="' + app.inputTextField.text + '"></a>';
};
Большое спасибо! dimarik
Однако,
1. При добавлении весь текст, который там(1. Text Input (all text)) находится, уходит и остается только ссылка. //текст (вот ссылка) уходит//. Как сделать чтобы ссылка добавлялась к остальному тексту.
2. При следующем добавлении уже другой ссылки она не добавляется, а просто изменяется прошлая. Как сделать, чтобы можно было бы добавлять больше одной ссылки.
Спустя время (1 мин)
Проблему решил немного подредактировав
var app: Object = this;
var outputTextField: TextField;
var inputTextField: TextField;
this.button.onRelease = function():Void {
app.outputTextField.text = app.outputTextField.text + '<a href="' + app.inputTextField.text + '"></a>';
};
app.outputTextField.text += '<a href="' + app.inputTextField.text + '"></a>';
Спасибо
Последний 3 вопрос
Если я добавляю ссылку, то она всегда добавляется в конце всего текста(или др. ссылок)
Так как и
1. Text Input (all text)
2. Text Input (www.something.com)
это Text Input, то я могу ставить курсор в любой области текста 1. Text Input (all text), однако добавляется ссылка все равно в конце.
Как сделать так чтобы ссылка добавляласть там где стоит текстовый курсор.
var app: Object = this;
var outputTextField: TextField;
var inputTextField: TextField;
this.button.onRelease = function():Void {
var result: String;
var inline: String = '<a href="' + app.inputTextField.text + '"></a>';
if ( Selection.getFocus() == app.outputTextField ) {
var index:Number = Selection.getCaretIndex();
result =
app.outputTextField.text.slice(0, index) +
inline +
app.outputTextField.text.slice(index + 1);
} else {
result = app.outputTextField.text + inline;
}
app.outputTextField.text = result;
};
Что-то все равно, в конце только добавляет
Вот some.fla&some.swf //f8 as2
see swf (http://megaswf.com/view/4daaddc0140de74da511e1621c3d9909.html)
some.fla (http://narod.ru/disk/10905736000/some.fla.html)
some.swf (http://narod.ru/disk/10905747000/some.swf.html)
Я не учел, что фокус перемещается на кнопку. Нужно сохранять caretIndex.
var app: Object = this;
var outputTextField: TextField;
var inputTextField: TextField;
var caretIndex: Number = -1;
Key.addListener(this);
this.button.onRelease = function():Void {
var result: String;
var inline: String = '<a href="' + app.inputTextField.text + '"></a>';
if ( app.caretIndex > -1 ) {
result =
app.outputTextField.text.slice(0, app.caretIndex) +
inline +
app.outputTextField.text.slice(app.caretIndex + 1);
} else {
result = app.outputTextField.text + inline;
}
app.outputTextField.text = result;
};
function storeCaretIndex():Void {
if ( Selection.getFocus() != String(this.outputTextField) ) return;
this.caretIndex = Selection.getCaretIndex();
trace(this.caretIndex);
}
//-----------------------------------
//
// Events handlers
//
//-----------------------------------
function onKeyUp():Void {
this.storeCaretIndex();
}
function onMouseDown():Void {
this.onEnterFrame = this.enterFrameHandler;
}
function enterFrameHandler():Void {
this.onEnterFrame = null;
this.storeCaretIndex();
}
КрасавчеГ nice work
Добавлено через 2 часа 58 минут
Простите за упрямство, а если нужно сделать, так:
http://img194.**************/img194/8091/50754297.gif
т. е. если, 2. Text Input, уже не нужен, текс(ссылки) добавляются
непосредственно в 1. Text Input (all text) //ко всему(основному) тексту.
Спасибо.
Посмотрите, у класса Selection есть методы getBeginIndex() и getEndIndex().
Посидел, много error's набрал и понял что пока мозгов моиз не хватает,
поиск много чего дает(кому-то), но изменить, пока тоже не получается.
Вся надежда на тебя !-) Люди, нужна поддержка...
Как же надо изменить КОД, на что-то типа этого?
(Помогите, я только начал изучать AS (10 дней назад, сразу как закрыл сессию и перешел на 2 курс))
...
var outputTextField: TextField;
var caretIndex: Number = -1;
a=Selection.getBeginIndex();
b=Selection.getEndIndex();
Key.addListener(this);
this.button.onRelease = function():Void {
var result: String;
var inline: String = '<a href="' + tf_txt.getTextFormat(a,b) + '"></a>';
...
codfelix
15.07.2009, 06:43
Присоединяюсь к вопросу.
Кто-нибудь может помочь.
Можешь так попробовать.
var outputTextField:TextField;
var startIndex:Number;
var endIndex:Number;
var txt:String;
btn.onPress = rep_select;
function rep_select():Void {
startIndex = Selection.getBeginIndex();
endIndex = Selection.getEndIndex();
txt = outputTextField.text.substring(startIndex, endIndex);
trace(txt);
outputTextField.replaceText(startIndex,endIndex,'<a href="'+txt+'"></a>');
}
codfelix
15.07.2009, 12:14
// Как должен выглядеть КОД полностью, так не срабатывает,
var caretIndex: Number = -1;
var outputTextField:TextField;
var startIndex:Number;
var endIndex:Number;
var result:String;
Key.addListener(this);
this.btn.onRelease = function():Void {
startIndex = Selection.getBeginIndex();
endIndex = Selection.getEndIndex();
txt = outputTextField.text.substring(startIndex, endIndex);
};
function storeCaretIndex():Void {
if ( Selection.getFocus() != String(this.outputTextField) ) return;
this.caretIndex = Selection.getCaretIndex();
trace(this.caretIndex);
}
//-----------------------------------
//
// Events handlers
//
//-----------------------------------
function onKeyUp():Void {
this.storeCaretIndex();
}
function onMouseDown():Void {
this.onEnterFrame = this.enterFrameHandler;
}
function enterFrameHandler():Void {
this.onEnterFrame = null;
this.storeCaretIndex();
}
// КОД dimarik-а работает, как его изменить.
var app: Object = this;
var outputTextField: TextField;
var inputTextField: TextField;
var caretIndex: Number = -1;
Key.addListener(this);
this.button.onRelease = function():Void {
var result: String;
var inline: String = '<a href="' + app.inputTextField.text + '"></a>';
if ( app.caretIndex > -1 ) {
result =
app.outputTextField.text.slice(0, app.caretIndex) +
inline +
app.outputTextField.text.slice(app.caretIndex + 1);
} else {
result = app.outputTextField.text + inline;
}
app.outputTextField.text = result;
};
function storeCaretIndex():Void {
if ( Selection.getFocus() != String(this.outputTextField) ) return;
this.caretIndex = Selection.getCaretIndex();
trace(this.caretIndex);
}
//-----------------------------------
//
// Events handlers
//
//-----------------------------------
function onKeyUp():Void {
this.storeCaretIndex();
}
function onMouseDown():Void {
this.onEnterFrame = this.enterFrameHandler;
}
function enterFrameHandler():Void {
this.onEnterFrame = null;
this.storeCaretIndex();
}
кат-то так можно
var app: Object = this;
var pattern: String = '<a href="{s}"></a>';
var outputTextField: TextField;
var beginIndex: Number = -1;
var endIndex: Number = -1;
this.button.onRelease = function():Void {
if (app.beginIndex == -1 ||
app.endIndex <= app.beginIndex
) return;
Selection.setFocus( String(app.outputTextField) );
Selection.setSelection(app.beginIndex, app.endIndex);
var inline: String = app.substitute
(
pattern,
app.outputTextField.text.slice(app.beginIndex, app.endIndex)
);
app.outputTextField.replaceSel(inline);
};
this.outputTextField.onMouseUp =
this.outputTextField.onKeyUp = function():Void {
app.beginIndex = Selection.getBeginIndex();
app.endIndex = Selection.getEndIndex();
};
this.outputTextField.onSetFocus = function():Void {
Key.addListener(this);
Mouse.addListener(this);
};
this.outputTextField.onKillFocus = function():Void {
Key.removeListener(this);
Mouse.removeListener(this);
};
function substitute():String {
var temp: Array = arguments[0].split('{s}');
var i: Number = temp.length;
if (i-- > 1) while (i--) temp[i] += arguments[i + 1];
return temp.join('');
}
Работает на vBulletin ® версия 3.7.3. Copyright ©2000-2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Copyright © 1999-2008 Flasher.ru. All rights reserved.