Comunidad de diseño web y desarrollo en internet online

Tween sobre uint para hacer texto que se escribe por letra

Citar            
MensajeEscrito el 08 Jun 2010 08:13 pm
Tengo un serio problema estoy tratando de implementar los tween con otras propiedades, no las comunes por ejemplo "alpha", "x", etc, lo cual escribiendo en linea de tiempo no tuve ningun inconveniente pero el problema resulta cuando lo quiero armar en alguna clase y me tira el siguiente error:

ReferenceError: Error #1056: No se puede crear la propiedad nChar en Refresh_texto.
at fl.transitions::Tween/setPosition()
at fl.transitions::Tween/set position()
at fl.transitions::Tween()
at Refresh_texto(

el codigo es el siguiente:

Código ActionScript :

package 
{
   import fl.transitions.*
       import fl.transitions.easing.*
   import fl.transitions.TweenEvent;
   import flash.display.Sprite;
   import flash.display.MovieClip;
   import flash.text.TextField;
   import flash.text.TextFieldType;

   
   
   public class Refresh_texto extends Sprite
   {
      var sText:String = new String;
      var nChar:uint = new uint;
      var tText:Tween;
      var txt:TextField = new TextField();

      
      public function Refresh_texto() {
         txt.type = TextFieldType.DYNAMIC;
         txt.width = 200;
         txt.height = 100;
         this.addChild(txt);
         
         nChar = 0;
         sText = "este es el string que contiene texto que se va a escribir letra por letra mediante un tween blablablablablabla";

         tText = new Tween( this, "nChar", Regular.easeIn, 0, sText.length, 2, true);

          tText.addEventListener( TweenEvent.MOTION_CHANGE, changeTXT );
      
      }

   
      public function changeTXT (e:TweenEvent):void 
      {
         
         txt.text = sText.substr(0, nChar);

         
      }

   }
   
}


La verdad ya me estoy volviendo loco con esto, ya que como dije, en linea de tiempo funciona a la perfeccion
Codigo en linea de tiempo

Código ActionScript :

import fl.transitions.*
import fl.transitions.easing.*

var sText:String = "este es el string que contiene texto que se va a escribir letra por letra mediante un tween blablablablablabla";
var nChar:uint = 0;


var tText:Tween = new Tween( this, "nChar", Regular.easeOut, 0, sText.length, 2, true);
tText.addEventListener( TweenEvent.MOTION_CHANGE, refresh_texto );


function refresh_texto(e:TweenEvent):void {
   txt.text = sText.substr(0, nChar);
}


Bueno muchas gracias amigos.

Por rscn

8 de clabLevel



 

chrome
Citar            
MensajeEscrito el 09 Jun 2010 06:53 am
Tu "variable" nChar, al no haber indicado lo contrario es una variable privada. Esto es, sólo accesible desde la clase. Es por eso que te da error. Las dos opciones que tienes son
1.-Declarar la variable como pública

Código ActionScript :

public var nChar:uint = new uint;  //<---la declaramos como públicva

2.-Hacer unas funciones getter setter que controlen esa variable y hacer el tween sobre esa función gettes

Código ActionScript :

//En tu clase
public function set _nChar(n:uint):void 
{
       nChar = n;
}
public function get _nChar():uint
{
       return nChar;
}

El Tween lo harías sobre "_nChar"

Por Eliseo2

710 de clabLevel



 

firefox
Citar            
MensajeEscrito el 09 Jun 2010 01:59 pm
que grande Eliseo2, problema solucionado, muchas gracias.

Por rscn

8 de clabLevel



 

chrome

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.