Jdrumm
Jdrumm

Reputation: 45

AS3: Strings as variables

I'm creating an app that places pseudo-orders for pizza in my interaction design class. I've been doing well so far, but I've hit a roadblock. I'm new to actionscript.

The problem with the code below is not necessarily the structure, I simply have strings as variables that I equate with a specific topping type for the pizza being ordered and then when you click submit order btn it posts the results of the vars to the order summary screen and they are sent to their specific output boxes. The problem is that when a user doesn't click on ALL the meat_type(s) I get a error saying that parameter must be non-null. So how do I fix this issue. Am I looking for a giant switch statement that switches an all-encompassing variable? If so, how would I implement it, for instance (if condition1 is met, then would I empty out the string with " " ?

Any thoughts or help at all would be much appreciated. Thanks in advance.

(I've left out the listeners and the bulk of the code to keep it short, but the core concept is still here)

var meat_type1:String;
var meat_type2:String;//////////setting each type of meat topping to a string  

function addPepperoni (e:MouseEvent): void      
 {
   meat_type1 = "pepperoni"; 
 }

function addSausage (e:MouseEvent): void      
 {
   meat_type2 = "sausage"; 
 }

function clickSubmitOrder (e:MouseEvent): void
 {
myOrderSCREEN_MC.output_sub1.text = meat_type1;//sends result to their specific output box
myOrderSCREEN_MC.output_sub2.text = meat_type2;
 }

Upvotes: 1

Views: 98

Answers (1)

Andrew Sellenrick
Andrew Sellenrick

Reputation: 1016

If I understand the question I believe you could solve you error by simply defining the variable like this.

var meat_type1:String = "";
var meat_type2:String = "";

That way when you submit the order neither variable will be null.

Upvotes: 2

Related Questions