I am trying to write a Event listener and function to output my text from my associative array whenever a button is clicked. I think I'm relatively close to how it should be but I am having trouble with the function part. My teacher gave us a guide and it's different than what we worked on in class so it has me pretty confused.
Here is my code
//Associative array with an indexed array
//Array constructor:
var desserts:Array = new Array();
//Format:
//array titleNoSpaces
desserts["PistachioFluffFruitSalad"] = ["Pistachio Fluff Fruit Salad", "1 can Crushed pineapple with juice", "1 package Instant pistachio pudding mix", "1 container Whipped topping, thawed", "2 bananas, sliced", "2 cups mini marshmallows", "1 can fruit cocktail, drained", "1 can mandarin oranges, drained" ];
desserts["CoconutCreamPieIV"] = ["Coconut Cream Pie IV", "3/4 cup White Sugar", "1/4 cup Cornstarch", "1/4 tsp Salt", "2 cups Milk", "3 Egg Yolks", "2 tbsp Butter", "1 tsp Vanilla Extract", "1 cup Flaked Coconut", "1 Pie Shell, baked", "3 Egg Whites", "6 tbsp White Sugar" ];
desserts["EasySugarCookies"] = ["Easy Sugar Cookies", "2 and 3/4 cups All-purpose Flour", "1 tsp Baking Soda", "1/2 tsp Baking Powder", "1 cup Butter, Softened", "1 and 1/2 cups White Sugar", "1 Egg", "1 tsp Vanilla Extract" ];
desserts["ChocolateMeringuePie"] = ["Chocolate Meringue Pie", "1 Pie crust, baked", "1 cup White Sugar", "2 tbsp Unsweetened Cocoa Powder", "2 tbsp All-Purpose Flour", "1 pinch salt", "2 Eggs, separated", "1 cup Milk", "1 tbsp Butter", "1 tsp Vanilla Extract", "1/4 cup White Sugar"];
desserts["SweetAndSaltyCaramelApples"] =["Sweet and Salty Caramel Apples", "6 Granny Smith Apples", "6 Wooden Sticks", "1 package Individually wrapped caramels, unwrapped", "2 tbsp water", "1/2 tsp Vanilla Extract", "1 1/2 tbsp coarse sea salt", "1 cup Semisweet Chocolate Chips"];
//Output data:
// |--Dynamic text field instance name
// | array titleNoSpaces ingredient's index number
text_headline.text = desserts.PistachioFluffFruitSalad[0];
text_headline.text = desserts.CoconutCreamPieIV[0];
text_headline.text = desserts.EasySugarCookies[0];
text_headline.text = desserts.ChocolateMeringuePie[0];
text_headline.text = desserts.SweetAndSaltyCaramelApples[0];
//Output for ingredients
text_bigfield.htmlText = desserts.PistachioFluffFruitSalad[1] + "<br>" + desserts.PistachioFluffFruitSalad[2] + "<br>" + desserts.PistachioFluffFruitSalad[3] + "<br>" + desserts.PistachioFluffFruitSalad[4] + "<br>" + desserts.PistachioFluffFruitSalad[5] + "<br>" + desserts.PistachioFluffFruitSalad[6] + "<br>" + desserts.PistachioFluffFruitSalad[7];
text_bigfield.htmlText = desserts.CoconutCreamPieIV[1] + "<br>" + desserts.CoconutCreamPieIV[2] + "<br>" + desserts.CoconutCreamPieIV[3] + "<br>" + desserts.CoconutCreamPieIV[4] + "<br>" + desserts.CoconutCreamPieIV[5] + "<br>" + desserts.CoconutCreamPieIV[6] + "<br>" + desserts.CoconutCreamPieIV[7] + "<br>" + desserts.CoconutCreamPieIV[8] + "<br>" + desserts.CoconutCreamPieIV[9] + "<br>" + desserts.CoconutCreamPieIV[10] + "<br>" + desserts.CoconutCreamPieIV[11];
text_bigfield.htmlText = desserts.EasySugarCookies[1] + "<br>" + desserts.EasySugarCookies[2] + "<br>" + desserts.EasySugarCookies[3] + "<br>" + desserts.EasySugarCookies[4] + "<br>" + desserts.EasySugarCookies[5] + "<br>" + desserts.EasySugarCookies[6] + "<br>" + desserts.EasySugarCookies[7];
text_bigfield.htmlText = desserts.ChocolateMeringuePie[1] + "<br>" + desserts.ChocolateMeringuePie[2] + "<br>" + desserts.ChocolateMeringuePie[3] + "<br>" + desserts.ChocolateMeringuePie[4] + "<br>" + desserts.ChocolateMeringuePie[5] + "<br>" + desserts.ChocolateMeringuePie[6] + "<br>" + desserts.ChocolateMeringuePie[7] + "<br>" + desserts.ChocolateMeringuePie[8] + "<br>" + desserts.ChocolateMeringuePie[9] + "<br>" + desserts.ChocolateMeringuePie[10];
text_bigfield.htmlText = desserts.SweetAndSaltyCaramelApples[1] + "<br>" + desserts.SweetAndSaltyCaramelApples[2] + "<br>" + desserts.SweetAndSaltyCaramelApples[3] + "<br>" + desserts.SweetAndSaltyCaramelApples[4] + "<br>" + desserts.SweetAndSaltyCaramelApples[5] + "<br>" + desserts.SweetAndSaltyCaramelApples[6] + "<br>" + desserts.SweetAndSaltyCaramelApples[7];
btn_pistachio.addEventListener(MouseEvent.CLICK, pistachiotext);
btn_coconut.addEventListener(MouseEvent.CLICK coconuttext);
btn_cookie.addEventListener(MouseEvent.CLICK cookietext);
btn_chocolate.addEventListener(MouseEvent.CLICK chocolatetext);
btn_caramelapple.addEventListener(MouseEvent.CLICK caramelappletext);
function pistachiotext(event:MouseEvent){
text_headline.text[0]
text_bigfield.htmlText[1]
}
function coconuttext(event:MouseEvent){
text_headline.text[0]
text_bigfield.htmlText[2]
}
function cookietext(event:MouseEvent){
text_headline.text[0]
text_bigfield.htmlText[3]
}
function chocolatetext(event:MouseEvent){
text_headline.text[0]
text_bigfield.htmlText[4]
}
function caramelappletext(event:MouseEvent){
text_headline.text[0]
text_bigfield.htmlText[5]
}
I know there's something funky with the functions but I can't quite figure what. I've been googling around and looking through my book(that my teacher required and never taught from). The fact that he changed up how we were doing this and didn't really go over this new way has really thrown me off.
with the way everything is typed now I'm getting compiler errors:
Scene 1, Layer 'Actions', Frame 1, Line 31 1084:Syntax error: expecting rightparen before coconuttext. Scene 1, Layer 'Actions', Frame 1, Line 32 1084:Syntax error: expecting rightparen before cookietext. Scene 1, Layer 'Actions', Frame 1, Line 33 1084:Syntax error: expecting rightparen before chocolatetext. Scene 1, Layer 'Actions', Frame 1, Line 31 1084:Syntax error: expecting rightparen before caramelappletext.
Edit: I am now getting the output error: ReferenceError: Error #1069: Property 1 not found on String and there is no default value. at KaraRichardsonRecipesDigitalA1_fla::MainTimeline/pistachiotext()
what does this error mean?