1

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;
 }
3
  • Please post the answer and mark it as correct when you are able to. Helps keep the system clean and will help any user who stumbles upon this question through Google or similar. Commented Mar 26, 2014 at 23:35
  • Please excuse my last comment, this problem is still blocking my way. I implemented a switch statement based on the user input for selecting a specific topping and it didn't take care of the problem. Commented Mar 26, 2014 at 23:57
  • You could check each meat_type variable is not null before attempting to act on it. if (meat_type2 != null) { // do something with meat_type } Commented Mar 27, 2014 at 0:38

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Andrew, can't believe I didn't try that. That leads me confirm that I was originally correct when I said that I was over-thinking it. The first thing I thought of was using a switch and that was obviously overkill.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.