• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Typing text with a button in createJS on animateCC

Guest
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

Hi,

I start in CreateJS.. My code doesn't work and I need help.

I wish to realize a virtual keyboard. The goal is to enter the correct 4-digit code, using the different buttons (from 0 to 9). The C key deletes the digits.

How to make a button that displays text on the click?

Here is the prototype online (.fla ...): http://absolu-sport.fr/animations/

Thanks a lot for your help ! Matt

//Référence du scénario
_this
= this;

//Curseur souris
stage
.enableMouseOver();

//Gestion du touché sur tablette/mobile
createjs
.Touch.enable(stage);

//Variables
var passKey = "1234";
var displayText;
var displayAccessText;

function numDisplay(num) {
  
if (displayText.length < 5)
  
{
  displayAccessText
="";
  displayText
+=num;
  displayNum
.text = displayText;
  displayAccess
.text= displayAccessText;
  
}
}


_this
.key1.addEventListener("mousedown", clicknum1);
_this
.key2.addEventListener("mousedown", clicknum2);
_this
.key3.addEventListener("mousedown", clicknum3);
_this
.key4.addEventListener("mousedown", clicknum4);
_this
.key5.addEventListener("mousedown", clicknum5);
_this
.key6.addEventListener("mousedown", clicknum6);
_this
.key7.addEventListener("mousedown", clicknum7);
_this
.key8.addEventListener("mousedown", clicknum8);
_this
.key9.addEventListener("mousedown", clicknum9);
_this
.key0.addEventListener("mousedown", clicknum0);
_this
.keycancel.addEventListener("mousedown", clicknumc);
_this
.keyenter.addEventListener("mousedown", clicknumenter);


function clicknum1() {
numDisplay
("1");
}

function clicknum2() {
numDisplay
("2");
}

function clicknum3() {
numDisplay
("3");
}

function clicknum4() {
numDisplay
("4");
}

function clicknum5() {
numDisplay
("5");
}

function clicknum6() {
numDisplay
("6");
}

function clicknum7() {
numDisplay
("7");
}

function clicknum8() {
numDisplay
("8");
}

function clicknum9() {
numDisplay
("9");
}

function clicknum0() {
numDisplay
("0");
}

function clicknumc() {
displayText
= "";
displayNum
.text= displayText;  
}

function clicknumenter() {
  
if (displayText==passKey) {
  displayText
="";
  displayAccess
.text="TRUE";
  
}
  
else {
  displayText
="";
  displayAccessText
="FALSE";
  displayAccess
.text=displayAccessText;
  displayNum
.text = displayText;
  
}
}

Views

184

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
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 12, 2019 Feb 12, 2019

I don't have time to scrutinize all that code, but the first thing that jumped out at me is that you're trying to add to an uninitialized variable (displayText).

Votes

Translate

Translate
LEGEND ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

I don't have time to scrutinize all that code, but the first thing that jumped out at me is that you're trying to add to an uninitialized variable (displayText).

Votes

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
community guidelines
Guest
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

Hi,

Yes thank you!

Correct code here :

//Référence du scénario

_this = this;

//Curseur souris

stage.enableMouseOver();

//Gestion du touché sur tablette/mobile

createjs.Touch.enable(stage);

//Variables

passKey = "1234";

displayText= "";

displayAccessText= "";

function numDisplay(num) {

if (displayText.length < 5)

{

displayAccessText;

displayText +=num;

_this.displayNum.text = displayText;

_this.displayAccess.text= displayAccessText;

_this.displayAccess.text="";

}

}

_this.key1.addEventListener("mousedown", clicknum1);

_this.key2.addEventListener("mousedown", clicknum2);

_this.key3.addEventListener("mousedown", clicknum3);

_this.key4.addEventListener("mousedown", clicknum4);

_this.key5.addEventListener("mousedown", clicknum5);

_this.key6.addEventListener("mousedown", clicknum6);

_this.key7.addEventListener("mousedown", clicknum7);

_this.key8.addEventListener("mousedown", clicknum8);

_this.key9.addEventListener("mousedown", clicknum9);

_this.key0.addEventListener("mousedown", clicknum0);

_this.keycancel.addEventListener("mousedown", clicknumc);

_this.keyenter.addEventListener("mousedown", clicknumenter);

function clicknum1() {

numDisplay("1");

}

function clicknum2() {

numDisplay("2");

}

function clicknum3() {

numDisplay("3");

}

function clicknum4() {

numDisplay("4");

}

function clicknum5() {

numDisplay("5");

}

function clicknum6() {

numDisplay("6");

}

function clicknum7() {

numDisplay("7");

}

function clicknum8() {

numDisplay("8");

}

function clicknum9() {

numDisplay("9");

}

function clicknum0() {

numDisplay("0");

}

function clicknumc() {

displayText = "";

_this.displayNum.text= displayText;

}

function clicknumenter() {

if (displayText==passKey) {

displayText="";

_this.displayNum.text="";

_this.displayAccess.text="TRUE";

}

else {

displayText="";

displayAccessText="FALSE";

_this.displayAccess.text=displayAccessText;

_this.displayNum.text = displayText;

}

}

Votes

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
community guidelines
LEGEND ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

Well now you've converted a bunch of variables to globals, which may work, but is bad practice.

Votes

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
community guidelines
Guest
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

LATEST

Ok thanks!

Just that ?

//Variables

var passKey = "1234";

var displayText= "";

var displayAccessText= "";

Votes

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
community guidelines