Skip to main content
Known Participant
July 14, 2020
Question

text input as3 to html5

  • July 14, 2020
  • 7 replies
  • 441 views

///////////////////////////////////////////////////// RANDOM
function getRandomSequence2(min: int, max: int): Array {
if (min > max) throw new Error("Max value should be greater than Min value!");
if (min == max) return [min];
var values: Array = [];
for (var i: int = min; i <= max; i++) values.push(i);
var result: Array = [];
while (values.length > 0) result = result.concat(values.splice(Math.floor(Math.random() * values.length), 1));
return result;
}
var randomicos: Array = new Array();
randomicos = getRandomSequence2(1, 10);//PEGA O X
/////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////

String.prototype.removeSpaces = function ():String {
var str = this;
while(str.indexOf(' ') > -1)
str = str.split(' ').join(' ');
return str;
}
function textRemoveSpaces(e:Event) {
var current = e.currentTarget;
current.text = current.text.removeSpaces();
}
txt.addEventListener('change', textRemoveSpaces); //Deixa letras maiusculas

///////////////////////////////////////////////////////////////////////////////////////

import flash.ui.Multitouch;
import flash.events.Event;

stop();

//////////////////////////////////////////////////////////////////////////
txt.addEventListener(Event.CHANGE, toUpperCase)

function toUpperCase(evt: Event): void {

evt.target.text = evt.target.text.toUpperCase();
}

//palavras acentos.
txt.restrict = "A-Z\\-\u00C0-\u00FF";
//////////////////////////////////////////////////////////////////////////
var contador:Number=0;
var errado:Number=0;

var respostas:Array=new Array(
"","CARLA","BRINCANDO","ESCUTEI","MIADO","ESCOLHER","BRASIL","URNA","NAÇÃO","INDEPENDENTE","FORMA");

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function INICIO():void{
txt.maxChars=respostas[randomicos[contador]].length+1;
txt.text="";
txt.type='input';
txt.textColor=0xF5B13B;
//this.aparece.gotoAndStop(randomicos[contador])
trace("resposta= "+respostas[randomicos[contador]])
}

INICIO();

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

verificar.addEventListener('click',fnVerificar)
verificar.buttonMode=true;
/*DIGITA.alpha=0;*/

function fnVerificar(e:Event):void{

var qlq:Array=new Array(txt.text)
qlq[0]= qlq[0].replace(/^[\s|"]+|[\s|"]+$/gs, '');//FUNÇÃO QUE TIRA O ESPAÇO DO INICIO E DO FIM

if(qlq[0]==respostas[randomicos[contador]]){
trace("acertou")
txt.type='dynamic'
txt.textColor=0x009900;
//++contador;
verificar.removeEventListener('click',fnVerificar)
verificar.alpha=0.2;
}
else{
//++errado;
trace("errou")
//txt.type='dynamic'
//txt.textColor=0xFF0000;
}


}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

    This topic is closed to new replies. Start a new post to keep the conversation going.

    7 replies

    kglad
    Community Expert
    Community Expert
    July 14, 2020

    you have a question or are you looking for someone to work for you?

    Known Participant
    July 15, 2020

    I have a question!

    I can't do this programming in html5 canvas only on as3!

    But I'm migrating to html5 canvas and I'm having difficulty in this part of the input text with restrict maxchars and take space from the beginning.

    I need help with this cod. If you can help me I appreciate it.

    kglad
    Community Expert
    Community Expert
    July 15, 2020

    function removeLeadFollowSpacesF(s){

    return s.trim();

    }

    function removeAllSpacesF(s){

    return s.split(" ").join("");

    }

    function truncateF(s,maxChar){

    return s.substr(0,maxChar);

    }