Pregunta

Este es un problema con textField.htmlText en ActionScript 3.0 y la clase estoy haciendo para ello.

En un intento de no publicar toda mi clase, he logrado se reducen el problema a lo que parece ser un tema tonto y casi imposible-de superar. Parece que TextFields (en concreto, los creados con ActionScript) tienen un tiempo duro insoportablemente con un efecto de tipo de escritura creado por

myTextField.htmlText =  myString.substr(0, length);

donde la longitud es un incremento cada vez mayor. Vamos a obtener un ejemplo más específico, sin embargo. Para empezar, tenemos un poco de cadena aleatoria en el fotograma 1 de nuestro archivo fla:

var Text0:String = 'It wasn\'t like we didn\'t have love. John and I shared much of our love, but for some reason something went terribly wrong one day...\nWe talked less, we saw each other less, we hardly even got to know each other anymore. The love was dried up, and if I stayed I would have withered, and choked on words I could never share...';

Uso de mi clase, que se necesita para esta cadena y palabras clave X aplica etiquetas HTML Y en torno a esas palabras:

var textBuildah = new textBuilder(); //Class name, for this example, is textBuilder
Text0 = textBuildah.htmlModify(Text0, ['love', 'red'], ['we', '~#FCFE12']);

Esto toma Text0 (todavía estamos en las acciones de fotograma 1 aquí) y lo hace a él:

trace(Text0) // Outputs: It wasn't like <FONT COLOR="#FCFE12">we</FONT> didn't have <FONT COLOR="#FF0000">love</FONT>. John and I shared much of our <FONT COLOR="#FF0000">love</FONT>, but for some reason something <FONT COLOR="#FCFE12">we</FONT>nt terribly wrong one day... We talked less, <FONT COLOR="#FCFE12">we</FONT> saw each other less, <FONT COLOR="#FCFE12">we</FONT> hardly even got to know each other anymore. The <FONT COLOR="#FF0000">love</FONT> was dried up, and if I stayed I would have withered, and choked on words I could never share...

Estoy asumiendo que todas esas etiquetas HTML son correctos. A continuación, hacemos esto:

textBox.htmlText = Text0 //textBox is a text field that was put on the stage and named "textBox" using the properties window

Y se muestra exactamente como lo quiero (parte inferior derecha de la imagen) [i49.tinypic.com/2upts1v.jpg]. Añadir http:. // permitido verla

A continuación, me borra la línea de código anterior, y tratar lo siguiente:

var Length:Number = 0;
textBox.addEventListener(Event.ENTER_FRAME, writeText);

function writeText(e:Event):void {
    if (Length < Text0.length) {
        Length ++;
        e.currentTarget.htmlText = Text0.substring(0, Length);
        trace(e.currentTarget.htmlText+"\n"+e.currentTarget.name+"\n");
    } else {
        e.currentTarget.htmlText = Text0;
        e.currentTarget.removeEventListener(Event.ENTER_FRAME, writeText);
    }
}

Y, funciona como acaba de hacer textBox.htmlText = Text0;

A continuación, tratamos algo nuevo. Creamos un campo de texto con ActionScript, y aplicamos el mismo detector de eventos para que:

var LengthTwo:Number = 0;
var myTextField = new TextField();
myTextField.x = 100
myTextField.y = 100;
myTextField.width = 200;
myTextField.height = 150;
myTextField.wordWrap = true;

addChild(myTextField);

mytextField.addEventListener(Event.ENTER_FRAME, writeText);

function writeTextTwo(e:Event):void {
if (LengthTwo < Text0.length) {
    LengthTwo++;
    e.currentTarget.htmlText = Text0.substring(0, Length);
    trace(e.currentTarget.htmlText+"\n"+e.currentTarget.name+"\n");
} else {
    e.currentTarget.htmlText = Text0;
    e.currentTarget.removeEventListener(Event.ENTER_FRAME, writeText);
}
}

Se produce algo así como que se ve en el centro de esta imagen. [I49.tinypic.com/2upts1v.jpg]. Añadir http: // para verlo. Además, si bien los tipos, que cambia de color con frecuencia y disorientatingly. Hice un par de huellas, y me di cuenta de que el htmlText del myTextField tiene etiquetas adicionales al comienzo de la misma. He aquí una instantánea de una de las huellas:

<P ALIGN="LEFT"><FONT FACE="Times Roman" SIZE="12" COLOR="#FF0000" LETTERSPACING="0" KERNING="0">It wasn&apos;t like <FONT COLOR="#FCFE12">we</FONT> didn&apos;t have love. John and I shared much of our love, but for some reason something <FONT COLOR="#FCFE12">we</FONT>nt terribly wrong one day...</FONT></P><P ALIGN="LEFT"><FONT FACE="Times Roman" SIZE="12" COLOR="#FF0000" LETTERSPACING="0" KERNING="0">We talked less, <FONT COLOR="#FCFE12">we</FONT> saw each other less, <FONT COLOR="#FCFE12">we</FONT> hardly even got to know each other anymore. The love was dried up, and if I stayed I would have withered, and choked on words I could never share..</FONT></P>
instance5

<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Calibri" SIZE="10" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">It wasn&apos;t like <FONT COLOR="#FCFE12">we</FONT> didn&apos;t have <FONT COLOR="#FF0000">love</FONT>. John and I shared much of our <FONT COLOR="#FF0000">love</FONT>, but for some reason something <FONT COLOR="#FCFE12">we</FONT>nt terribly wrong one day...</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Calibri" SIZE="10" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">We talked less, <FONT COLOR="#FCFE12">we</FONT> saw each other less, <FONT COLOR="#FCFE12">we</FONT> hardly even got to know each other anymore. The <FONT COLOR="#FF0000">love</FONT> was dried up, and if I stayed I would have withered, and choked on words I could never share..</FONT></P></TEXTFORMAT>
textBox

Me he dado cuenta de que en todo este proceso, un campo de texto de poner en el escenario y conjunto para hacer etiquetas HTML mantendrá su comienzo etiquetas

<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Calibri" SIZE="10" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">

y simplemente realizar cambios en las piezas especificadas en el interior. Sin embargo, para un cuadro de texto añadido a través de ActionScript 3.0, se cambia cualquiera de los anteriores iniciadores-etiquetas como la función WriteText sigue y la subcadena empieza a incluir más y más etiquetas HTML.

¿Alguien tiene alguna idea de lo que me falta? ¿Hay una propiedad Necesito definir para deshacerse de este efecto raro?

Además, si la explicación era demasiado largo, esta es una. fla que produce exactamente el mismo problema que he estado teniendo . El campo de texto del medio es el problema. El textField en la esquina inferior derecha no es un problema.

Si usted no puede manejar fla que ha hecho para CS3 / 4, tienen la siguiente:

var Text0:String = 'It wasn\'t like <font color = "#FCFE12">we</font> didn\'t have <font color = "#FF0000">love</font>. John and I shared much of our <font color = "#FF0000">love</font>, but for some reason something <font color = "#FCFE12">we</font>nt terribly wrong one day...\nWe talked less, <font color = "#FCFE12">we</font> saw each other less, <font color = "#FCFE12">we</font> hardly even got to know each other anymore. The <font color = "#FF0000">love</font> was dried up, and if I stayed I would have withered, and choked on words I could never share...';
var myTextField:TextField = new TextField();
var Length:Number = 0;
var LengthTwo:Number = 0;
myTextField.x = 75;
myTextField.y = 100;
myTextField.width = 400;
myTextField.height = 150;
myTextField.wordWrap = true;
myTextField.textColor = 0xFFFFFF;
addChild(myTextField);

textBox.addEventListener(Event.ENTER_FRAME, writeText);
myTextField.addEventListener(Event.ENTER_FRAME, writeTextTwo);

function writeText(e:Event):void {
    if (Length < Text0.length) {
        Length ++;
        e.currentTarget.htmlText = Text0.substring(0, Length);
        trace(e.currentTarget.htmlText+"\n"+e.currentTarget.name+"\n");
    } else {
        e.currentTarget.htmlText = Text0;
        e.currentTarget.removeEventListener(Event.ENTER_FRAME, writeText);
    }
}

function writeTextTwo(e:Event):void {
if (LengthTwo < Text0.length) {
    LengthTwo++;
    e.currentTarget.htmlText = Text0.substring(0, Length);
    trace(e.currentTarget.htmlText+"\n"+e.currentTarget.name+"\n");
} else {
    e.currentTarget.htmlText = Text0;
    e.currentTarget.removeEventListener(Event.ENTER_FRAME, writeText);
}
}

Hasta ahora, he intentado fijar la TextFormat para myTextField justo debajo de la definición textField. Luego he intentado establecer un exterior específica TextFormat del campo. He intentado hacer el defaultTextFormat un nuevo formato, he intentado restablecer la hoja de estilo dentro de la función WriteText ... Ha sido un poco de una pesadilla logística para mí. No tengo idea de cómo detener los cambios de color extraños en el fla ...

El problema no sólo ocurren con color, sin embargo. Sucede con negrita, cursiva, etc., que usted pone en la función y el efecto de hacer eso Type-escritura sobre. Sin embargo, si usted acaba de establecer htmlText = x, entonces se ve bien.

¿Alguna idea?

EDIT: Parece que hay un pequeño problema con la aplicación de las mismas cosas que el uso de negrita, cursiva, subrayado, etc. Si alguien tiene alguna idea de cómo hacer eso con el texto anterior, o para crear un efecto similar usando htmlText con negrita, cursiva, etc - respuesta aquí

¿Fue útil?

Solución

Se puede ver en su IDE creado campo de texto que tiene un defecto TextFormat que está presente cada vez que cambie el texto que restablecer la fuente, color, tamaño, etc ..

Así que para su dinámica AS3 TextField crear un nuevo TextFormat con todo el formato que desea conservar y en ti detector de eventos simplemente restablecer la propiedad defaultTextFormat antes de que escribiendo:

var Text0:String = 'It wasn\'t like <font color = "#FCFE12">we</font> didn\'t have <font color = "#FF0000">love</font>. John and I shared much of our <font color = "#FF0000">love</font>, but for some reason something <font color = "#FCFE12">we</font>nt terribly wrong one day...\nWe talked less, <font color = "#FCFE12">we</font> saw each other less, <font color = "#FCFE12">we</font> hardly even got to know each other anymore. The <font color = "#FF0000">love</font> was dried up, and if I stayed I would have withered, and choked on words I could never share...';
var myTextField:TextField = new TextField();
var Length:Number = 0;
var LengthTwo:Number = 0;
myTextField.x = 75;
myTextField.y = 100;
myTextField.width = 400;
myTextField.height = 150;
myTextField.wordWrap = true;
addChild(myTextField);

// create a TextFormat
var tf:TextFormat = new TextFormat("Calibri", 10, 0xffffff);

myTextField.addEventListener(Event.ENTER_FRAME, writeTextTwo);

function writeTextTwo(e:Event):void {
  if (LengthTwo < Text0.length) {
    LengthTwo++;

    // reset the default TextFomat
    e.currentTarget.defaultTextFormat = tf;

    e.currentTarget.htmlText = Text0.substring(0, Length);
    trace(e.currentTarget.htmlText+"\n"+e.currentTarget.name+"\n");
  } else {
    e.currentTarget.htmlText = Text0;
    e.currentTarget.removeEventListener(Event.ENTER_FRAME, writeText);
  }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top