Skip to main content
Participant
July 16, 2017
Answered

Action Script error 1006 in output

  • July 16, 2017
  • 1 reply
  • 663 views

Hello there, I am quite new to Action Script 3.0 and I seem to have some complications with my coding. It works fine when I test it in the movie; however, when I put an amount over 150, I get an output error #1006: value is not a function. I am pretty sure my problem is in the last two "else if" statements since I am trying to make the answer of the equation appear when I put an amount over 150 mins. Any help will be much appreciated.

Inline image 1

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

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

btnCalculate.addEventListener(MouseEvent.CLICK, determineCost);

// These lines make the textinput and the radioButtons wait for a mouse click

// When these components are clicked, the clearLabels function is called

txtinMass.addEventListener(MouseEvent.CLICK, clearLabels); FirstRadio.addEventListener(MouseEvent.CLICK, clearLabels);

SecondRadio.addEventListener(MouseEvent.CLICK, clearLabels);

// This is the determineCost function

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

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

function determineCost(e:MouseEvent):void

{

// declare the variables

var Mass:uint;

var Firsts:String;

var Seconds:String;

// get the mass from the user

Mass = int(txtinMass.text);

// FirstGroup.group determines the group that FirstRadio is in

// .selectedData gets the value of the RadioButton that is selected from the group

Firsts = String(FirstRadio.group.selectedData);

Seconds = String(SecondRadio.group.selectedData);

// determine the cost

if (Mass <= 30 && Firsts == "First Class")

{

lblCost.text = "0.38";

}

else if (Mass <= 30 && Seconds == "Second Class")

{

lblCost.text = "0.28";

}

else if (Mass > 30 && Mass <= 50 && Firsts == "First Class")

{

lblCost.text = "0.55";

}

else if (Mass > 30 && Mass <= 50 && Seconds == "Second Class")

{

lblCost.text = "0.40";

}

else if (Mass > 50 && Mass <= 100 && Firsts == "First Class")

{

lblCost.text = "0.73";

}

else if (Mass > 50 && Mass <= 100 && Seconds == "Second Class")

{

lblCost.text = "0.55";

}

else if (Mass > 100 && Firsts == "First Class")

{

lblCost.text = (0.73 + 0.24 * ((Mass - 100) / 50))();

}

else if (Mass > 100 && Seconds == "Second Class")

{

lblCost.text = (0.55 + 0.19 * ((Mass - 100) / 50))();

}

}

// This is the clearLabels function

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

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

function clearLabels(e:MouseEvent):void

{

lblCost.text = "";

txtinMass.text = "";

}

This topic has been closed for replies.
Correct answer Ned Murphy

In the last two sections you have an extra opening parenthesis that makes it appear as a function call...

();

lblCost.text = (0.73 + 0.24 * ((Mass - 100) / 50))();

lblCost.text = (0.55 + 0.19 * ((Mass - 100) / 50))();

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
July 16, 2017

In the last two sections you have an extra opening parenthesis that makes it appear as a function call...

();

lblCost.text = (0.73 + 0.24 * ((Mass - 100) / 50))();

lblCost.text = (0.55 + 0.19 * ((Mass - 100) / 50))();

Participant
July 16, 2017

Hey Ned, thanks for making the time to answer my question. I made changes based on the things you mentioned. Unfortunately, after I made those changes, an error appears "Implicit coercion of a value of type Number to an unrelated type string". The error seems to occur on the last two "else if" statements. Please tell me any changes I needed to do. Once again, your help is much appreciated.

Colin Holgate
Inspiring
July 16, 2017

The compiler is pointing out things that may not work. In this case it probably would work, but you can easily make the compiler happy by making it clear that you want it to be a string. Like this:

lblCost.text = String(0.73 + 0.24 * ((Mass - 100) / 50));