![]() |
|
||||||||||
|
|||||
|
Регистрация: Jun 2006
Сообщений: 1
|
Есть текстовое поле, возможно ли и как узнать координаты символа из этого поля с неким индексом i?
Зараннее спасибо... |
|
|||||
|
"человек"
Регистрация: Nov 2002
Адрес: +-
Сообщений: 1,807
|
дано текст поле:
---------- txt.text="слово текст текст\nгы ё текст текск"; ---------- разбиваем поле на 3 до символа "ё", получаем 3 новых текст. поля: ---------- "слово текст текст" + "\тгы" + "ё" +, остальное нам не нужно. ---------- собираем мазайку из полей (размещаем 3 поле относительно x, y, width, height 1 и 2 полей) ---------- "слово текст текст"(1) "гы"(2) + "ё"(3) ---------- берём коордтнату x y 3 поля =)
__________________
flash it |
|
|||||
|
Et cetera
Регистрация: Sep 2002
Сообщений: 30,787
|
Нет, нельзя.
|
|
|||||
|
"человек"
Регистрация: Nov 2002
Адрес: +-
Сообщений: 1,807
|
Можно только извратами =)
__________________
flash it |
|
|||||
|
вырезаем строку до нужной нам буквы, получаем ширину этой строки.
Совсем правильного лекарства нету, если допустим бить по буквам то это все зсивит от шрифта (нечертания и размера) |
|
|||||
|
Регистрация: Nov 2005
Сообщений: 221
|
Цитата:
Сложнее определить в какой строке находиться нужный символ. Если кто-либо не оставил это затею, могу попробовать привести пример как можно это сделать, правда через одно место... :)
__________________
Fiat lux |
|
|||||
|
Цитата:
/**
* @author Ilja
* class for create any text effects which use each char of textfield
*/
import fx.FxEffect;
class fx.effects.AbstractCharEffects {
private var model: TextField;
private var chars:Array;
private var container:MovieClip;
private var modelSpace:MovieClip;
private var copyProp:Array = ['autoSize', 'background','embedFonts','textColor','selectable'];
//-------------------
//private functions
//-------------------
/**
* function prepare effect
*@param numAr - count of chars array
*@return void
*/
private function init(numAr){
this.createChars(numAr);
this.model._visible = false;
}
/**
* function create array of movieclips with chars
*@return array with movieclips
*/
function getOneChars():Array{
var tmpCharArray = new Array();
var tfm:TextFormat= new TextFormat();
tfm = this.model.getTextFormat();
var chs:Array = this.model.text.split('');
var x:Number = 0;
var y:Number = 0;
var w:Number = 0;
var dy:Number = 0;
var dxs:Array = new Array();
var tmp:Array = this.model.text.split(chr(13));
if (tmp.length>1){
var k=0;
switch (tfm.align){
case 'center':
k=.5;
break;
case 'right':
k=1;
break;
default:
k=0;
break;
}
var max:Number=Number(0);
for (var i : Number = 0; i < tmp.length; i++) {
dxs[i] = Number(tfm.getTextExtent(tmp[i]).width);
if (dxs[i]>max) max=dxs[i];
}
for (var i : Number = 0; i < dxs.length; i++) {
dxs[i] = (max-dxs[i])*k;
}
}
else{
dxs.push(0);
}
var pos:Number=0;
for (var i : Number = 0; i < chs.length; i++) {
if (chs[i]==chr(13)){
pos++;
x=0;
y+=dy;
}else{
var t = this.container.getNextHighestDepth();
var mc:MovieClip = this.container.createEmptyMovieClip('tfmc'+t, t);
mc.createTextField('tf',1,0,0,10,0);
var tf:TextField = mc['tf'];
for (var j=0; j<this.copyProp.length;j++) {
tf[this.copyProp[j]] = this.model[this.copyProp[j]];
}
tf.text = chs[i];
tf.setTextFormat(tfm);
var ob = tfm.getTextExtent(chs[i]);
mc.defx = x+ob.width/2+dxs[pos];
mc._x = mc.defx;
x+=ob.width;
mc.defy = y+ob.height/2;
mc._y = mc.defy;
dy = ob.height;
mc.tf._x = -ob.width/2;
mc.tf._y = -ob.height/2;
tmpCharArray.push(mc);
}
}
return tmpCharArray;
}
/**
* function create array with chars arrays
*@param count - count of arrays
*@return Array with chars arrays
*/
function getMulChars(count):Array{
var tmpArray = new Array();
for (var i : Number = 0; i < count; i++) {
tmpArray.push(this.getOneChars());
}
return tmpArray;
}
/**
* function create chars array depend on count
*@param count - number of array
*@return void
*/
private function createChars(count:Number){
//if (this.modelSpace['fxcont']) this.modelSpace['fxcont'].removeMovieClip();
if (this.container!=undefined) this.container.removeMovieClip();
this.container = this.modelSpace.createEmptyMovieClip('fxcont'+this.modelSpace.getNextHighestDepth(), this.modelSpace.getNextHighestDepth());
count = (count) ? count : 1;
if (count>1){
this.chars = this.getMulChars(count);
}
else
{
this.chars = this.getOneChars();
}
}
//-------------------
// constructor
//-------------------
/**
* coustructor
*@param obj - referens on textfield;
*@param count - count of chars array;
*@return void
*/
function AbstractCharEffects(obj:TextField,count:Number){
this.modelSpace = obj._parent;
this.model = obj;
this.init(count);
}
/**
* function resume effect
*@return void;
*/
function resume(){
this.container._visible = true;
this.model._visible = false;
this.container.owner = this;
this.step();
this.container.onEnterFrame = function(){
this.owner.step();
};
}
/**
* function stop or remove effect
*@param e - indicate stop or remove effect, if true - effect removed
*@return void
*/
function stop(e:Boolean){
this.model._visible = true;
this.container._visible = false;
this.model._alpha = 100;
delete this.container.onEnterFrame;
if (e) {this.removeEffects();
}
}
/**
* function start effect
*@return void
*/
function start(){
this.container._visible = true;
this.model._visible = false;
this.setStartPosition();
this.container.owner = this;
this.container.onEnterFrame = function(){
this.owner.step();
};
}
/**
* function
*@param
*@return
*/
function setStartPosition(){
}
/**
* function doing one step of effect
*@param
*@return
*/
function step(){
this.model._visible = false;
}
/**
* function remove text effect
*@return void
*/
function removeEffects(){
for (var i : Number = 0; i < FxEffect.movies.length; i++) {
if (this.model._id==FxEffect.movies[i]){
FxEffect.movies.splice(i,1);
}
}
this.container.removeMovieClip();
}
}
|
|
|||||
|
Et cetera
Регистрация: Sep 2002
Сообщений: 30,787
|
FxEffect забыл
|
|
|||||
|
ага провтыкал, но это нестрашно - мочим этот импорт и метод removeEffects, они из другой оперы и к данному вопросу не относяться
|
![]() |
![]() |
Часовой пояс GMT +4, время: 12:52. |
|
|
« Предыдущая тема | Следующая тема » |
|
|