Hello,
i was using this typewriter function in as2 that launched the following way:
textfield1.typewriter(text1, "", 1);
text1 is the new text to animate, “” is the blank text, and 1 is the speed (there are 3 more values but they are not needed at this time)
now, in the as file called typewriter.as that used to be included using
#include "typewriter.as"
was the following code using prototype. This being a long piece of code, i do not expect anyone to convert all of it, i just need a push with two things. How to call that same function in as3, and how to write the beginning of this new class (without prototype since it seems it is not the proper way of doing it anymore). Below this sample, is the attempt i have made at writing the package. Thanks:
//************************************************************//
// A NICE TYPEWRITER TEXT EFFECT
//************************************************************//
trace("as load");
MovieClip.prototype.typewriter = function(newtext:String, oldtext:String, lspeed:Number, blinkdelay:Number, f, v):Void {
//trace(newtext+" newtext in as file");
//trace(oldtext+" oldtext in as file");
//trace(lspeed+" lspeed in as file");
this.charToUse = " ";
//
if (oldtext == null) {
oldtext = "";
}
this.temptext = oldtext;
this.counter = 0;
this.i = oldtext.length;
if (lspeed == null) {
lspeed = 1;
}
if (blinkdelay == null) {
blinkdelay = 31;
}
this.onEnterFrame = function():Void {
for (mylspeed=0; mylspeed<lspeed; mylspeed++) {
this.temptext = this.temptext+newtext.charAt(this.i);
if (newtext.charAt(this.i) == "<") {
htmlend = newtext.indexOf(">", this.i);
htmladd = htmlend-this.i;
this.i = this.i+htmladd;
this.temptext = newtext.substr(0, this.i);
continue;
}
this.i++;
}
this.txt.htmlText = this.temptext+this.charToUse;
if (this.i>=newtext.length) {
this.mybool = 1;
this.onEnterFrame = function():Void {
this.counter++;
this.mybool = !this.mybool;
if (this.mybool == true) {
this.txt.htmlText = this.temptext+this.charToUse;
} else {
this.txt.htmlText = this.temptext;
}
if (this.counter>=blinkdelay) {
this.txt.htmlText = this.temptext;
this.counter = 0;
this.blinkremove();
delete this["onEnterFrame"];
f(v);
}
};
}
};
};
//
//************************************************************//
// REMOVE THE MOVIECLIP USED FOR THE TYPEWRITER EFFECT
//************************************************************//
MovieClip.prototype.blinkremove = function():Void {
this.onEnterFrame = function():Void {
this._alpha = this._alpha-10;
this._visible = !this._visible;
if (this._alpha<=0) {
this.removeMovieClip();
}
};
};
//************************************************************//
//
//************************************************************//
/*
MovieClip.prototype.elasticEffect = function(prop:Object, speed:Number, f, param):Void {
this.isAnimating = true;
this.counter = 0;
for (i in prop) {
prop* = Math.round(prop*);
}
if (speed == undefined) {
speed = 0;
}
if (speed == 0) {
for (i in prop) {
this* = prop*;
}
this.isAnimating = false;
if (f != undefined) {
if (param != undefined) {
f(param);
} else {
f();
}
}
} else {
speed = Math.abs(speed);
// check the vector for similar values and remove them
// this code will make sure the elastic effect is applied
for (i in prop) {
if (this* == prop*) {
prop = removeObjectElement(prop, i);
}
}
if (prop != null) {
removeMovieClip(this.elastic_effect_temp_mc);
mc = this.createEmptyMovieClip("elastic_effect_temp_mc", this.getNextHighestDepth());
mc.onEnterFrame = function():Void {
var mcObj:MovieClip = this._parent;
var isEqual:Boolean = false;
for (i in prop) {
if (mcObj* != prop*) {
mcObj* += (prop*-mcObj*)/speed;
if (Math.abs(mcObj*-prop*)<1) {
mcObj.counter++;
}
if (Math.abs(mcObj*-prop*)<0.1 || mcObj.counter>=3) {
mcObj* = prop*;
}
} else {
isEqual = true;
}
}
if (isEqual == true) {
delete this.onEnterFrame;
removeMovieClip(this);
for (j in prop) {
mcObj[j] = prop[j];
}
if (f != undefined) {
if (param != undefined) {
f(param);
} else {
f();
}
}
mcObj.isAnimating = false;
}
};
} else {
if (f != undefined) {
if (param != undefined) {
f(param);
} else {
f();
}
}
mcObj.isAnimating = false;
}
}
};
function removeObjectElement(obj:Object, propertyName:String):Object {
var temp:Object = new Object();
var nrElem:Number = 0;
for (i in obj) {
if (i != propertyName) {
nrElem++;
temp* = obj*;
}
}
return (nrElem == 0 ? null : temp);
}
*/
my attempt at rewriting the package:
package com.as3classes{
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.events.Event;
//import flash.display.MovieClip;
import flash.display.Sprite;
import flash.text.*;
public class Typewriter extends TextField { // i am not sure what extends does but this felt like the proper one if anything
//public class Typewriter {
public function typewriterEffect(value1:String, value2:String, value3:String) {
//i don't know if writing it this way will allow me to write the function in the fla
//as i used to like textfield1.typewriter(value1, value2, value3)!!!!
}
}
}