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

The value of the label component does not show

Guest
Jul 28, 2017 Jul 28, 2017

Hello,

I am having trouble displaying the value of my label component. There are no errors in my code, but when I test it in the movie and press a button, the text or value that I assign on my label does not seem to appear. Please let me know what I did wrong in my coding, any help is appreciated.

This is my code:

Disclaimer: This is not the whole code, it is part of it. I am just showing you the section of my code where I am having trouble with.

Problem: I have assign a value for my label, but does not appear on the test movie when a button is clicked.

Name for each label on each function: First is lbltotalScore, Second is lblLowestScore, Third is lblhighestScore.

// This is the totalScore function

// golfScore array of numbers

// returns the total value in the array

function totalScore(golfScore):Number

{

var y:Number = 0;

for (var z:int=0; z<golfScore.length; z++)

{

y += golfScore;

lbltotalScore.text = "Total:" + golfScore;

}

return y;

}

// This is the lowestScore function

// golfScore array of numbers

// returns the lowest value in the array

function lowestScore(golfScore):Number

{

var a:Number = golfScore[0];

for (var b:int=1; b<golfScore.length; b++)

{

if (golfScore < a)

{

a = golfScore;

lblLowestScore.text = "Lowest Score:" + golfScore;

}

}

return y;

}

// This is the highestScore function

// golfScore array of numbers

// returns the highest value in the array

function highestScore(golfScore):Number

{

var c:Number = golfScore[0];

for (var d:int=1; d<golfScore.length; d++)

{

if (golfScore > c)

{

c = golfScore;

lblhighestScore.text = "Highest Score:" + golfScore;

}

}

return c;

}

TOPICS
ActionScript
298
Translate
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 ,
Jul 29, 2017 Jul 29, 2017

How do those functions relate to having clicked a button - they do not appear to be related to any clicking event?    What causes those functions to execute?

Translate
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
Jul 29, 2017 Jul 29, 2017

I have already created a button function early in my code for it to be clicked. These functions that I am showing to you gets value of total, lowest and highest value from the array. What I wanted to do is to put those values in my label, so that when I test it in the movie, they will appear.

Here is my entire code:

// This line makes the button, btnaddScore wait for a mouse click

// When the button is clicked, the addScore function is  called

btnaddScore.addEventListener(MouseEvent.CLICK, addScore);

// This line makes the textinput wait for a mouse click

// When this component is clicked, the clearLabels function is called

txtinScore.addEventListener(MouseEvent.CLICK, clearLabels);

// This line makes the button, btnDisplay wait for a mouse click

// When the button is clicked, the golfscores function is called

btnDisplay.addEventListener(MouseEvent.CLICK, golfscores);

// declare the global variables

var holeNumber:Number = 0; // array of holeNumber

var golfScore:Array = new Array(); // array of golf scores

var HoleNumber:Array = new Array(); // array of golf numbers

// This is the addScore function

// e:MouseEvent is the click event experienced by the button

// void indicates that the function does not return a value

function addScore(e:MouseEvent):void

{

// declare the variables

var Score:String; // score for each golf holes entered by the usert

Score = txtinScore.text; // get the score from the user

HoleNumber.push(Score); // append the number to the end of the array

golfScore.push(Score); // append the score to the end of the array

lblPrompt2.text = "Number of Golf Scores Entered: " + golfScore.length; // display the length of the array in the label

// sets the user to enter scores only up to 18 golf holes

holeNumber++;

if (holeNumber <= 17)

{

lblPrompt1.text = "Enter the score for hole #" + String(HoleNumber.length + 1) + ":";

}

else

{

lblPrompt1.text = "All scores are entered.";

txtinScore.text = "";

btnaddScore.enabled = false;

}

}

// This is the clearLabels function

// e:MouseEvent is the click event experienced by the textInput

// void indicates that the function does not return a value

function clearLabels(e:MouseEvent):void

{

txtinScore.text = "";

}

// This is the golfscores function

// e:MouseEvent is the click event experienced by the button

// void indicates that the function does not return a value

function golfscores(e:MouseEvent):void

{

lblPrompt3.text = "";

for (var x=0; x < golfScore.length; x++)

{

lblPrompt3.text += golfScore + "\r";

}

}

// This is the totalScore function

// golfScore array of numbers

// returns the total value in the array

function totalScore(golfScore):Number

{

var y:Number = 0;

for (var z:int=0; z<golfScore.length; z++)

{

y += golfScore;

lbltotalScore.text = "Total:" + golfScore;

}

return y;

}

// This is the lowestScore function

// golfScore array of numbers

// returns the lowest value in the array

function lowestScore(golfScore):Number

{

var a:Number = golfScore[0];

for (var b:int=1; b<golfScore.length; b++)

{

if (golfScore < a)

{

a = golfScore;

lblLowestScore.text = "Lowest Score:" + golfScore;

}

}

return y;

}

// This is the highestScore function

// golfScore array of numbers

// returns the highest value in the array

function highestScore(golfScore):Number

{

var c:Number = golfScore[0];

for (var d:int=1; d<golfScore.length; d++)

{

if (golfScore > c)

{

c = golfScore;

lblhighestScore.text = "Highest Score:" + golfScore;

}

}

return c;

}

I am referring to the last 3 functions in my code. Please let me know if I did this right and please let me know any changes I needed to do.

Translate
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 ,
Jul 30, 2017 Jul 30, 2017
LATEST

If that is all of the code you have, none of it is set up to call the functions you say have the labels.  Copy it all to a text editor and do a search for any one of the three function names.  You will not find anything outside of the functions that have those functions targeted.

If the intention is to have them react to having clicked something, you need to provide event listeners for them as well as needing to set up the functions to recognize the event.  Similar to what you did for the btnaddScore element

      btnaddScore.addEventListener(MouseEvent.CLICK, addScore);

     function addScore(e:MouseEvent):void ....etc

Translate
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