Highlighted

text input as3 to html5

Community Beginner ,
Jul 14, 2020

Copy link to clipboard

Copied

///////////////////////////////////////////////////// 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;
}


}

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

 

Views

76

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

text input as3 to html5

Community Beginner ,
Jul 14, 2020

Copy link to clipboard

Copied

///////////////////////////////////////////////////// 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;
}


}

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

 

Views

77

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 14, 2020 0
Adobe Community Professional ,
Jul 14, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 14, 2020 0
Community Beginner ,
Jul 15, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 15, 2020 0
Adobe Community Professional ,
Jul 15, 2020

Copy link to clipboard

Copied

function removeLeadFollowSpacesF(s){

return s.trim();

}

function removeAllSpacesF(s){

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

}

function truncateF(s,maxChar){

return s.substr(0,maxChar);

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 15, 2020 1
Community Beginner ,
Jul 15, 2020

Copy link to clipboard

Copied

Thank you helped me a lot that God doubles you!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 15, 2020 0
Adobe Community Professional ,
Jul 16, 2020

Copy link to clipboard

Copied

you're welcome.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 16, 2020 0
Community Beginner ,
Jul 22, 2020

Copy link to clipboard

Copied

how to use it in real time when typing and how would it look?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 22, 2020 0
kglad LATEST
Adobe Community Professional ,
Jul 23, 2020

Copy link to clipboard

Copied

use an "input" listener on your textfield to call those functions.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 23, 2020 0