-
Help, semester final project dew tomorrow! Help would be a dream come true!
Ok, so Im struggeling with transfering the data in a datagrid to a separate textfield on the next frame.
Ok this is how it looks on Frame 1:
var listeMat:Array = new Array();
var listeMatEkstra:Array = new Array();
listeMat[0]=liste.addItem({Vare:"Gulasjsuppe",Pris:20,antallsliderValue/2).toFixed(0)}) listeMat[1]=liste.addItem({Vare:"Potetlefser",Pris:15,antallsliderValue/2).toFixed(0)}) listeMat[2]=liste.addItem({Vare:"Laks",Pris:30,antallsliderValue/2).toFixed(0)})
listeMat[3]=liste.addItem({Vare:"Cottage Cheese",Pris:10,antallsliderValue/2).toFixed(0)}) listeMat[4]=liste.addItem({Vare:"Blåbærpai",Pris:25,antallsliderValue/2).toFixed(0)}) listeMat[5]=liste.addItem({Vare:"Kantarellsuppe",Pris:35,anta llsliderValue/2).toFixed(0)}) listeMat[6]=liste.addItem({Vare:"Brød",Pris:7,antallsliderValue/2).toFixed(0)})
listeMat[7]=liste.addItem({Vare:"Kvarg",Pris:17,antallsliderValue/2).toFixed(0)}) listeMat[8]=liste.addItem({Vare:"Salat",Pris:32,antallsliderValue/2).toFixed(0)})
Details: listeMat is the datagrid i would like to transfer the data to a textfield
listeMatEkstra[0]=listeEkstra.addItem({Vare:"Multeiskrem", pris:35}) listeMatEkstra[1]=listeEkstra.addItem({Vare:"Aioli", pris:5}) listeMatEkstra[2]=listeEkstra.addItem({Vare:"Granola", pris:15}) listeMatEkstra[3]=listeEkstra.addItem({Vare:"Gresskarkake", pris:20}) listeMatEkstra[4]=listeEkstra.addItem({Vare:"Fruktfat", pris:50}) listeMatEkstra[5]=listeEkstra.addItem({Vare:"Ørret", pris:40})
btnLeggTil.addEventListener(MouseEvent.CLICK, LeggTil) btnSlett.addEventListener(MouseEvent.CLICK, Slett) btnTotal.addEventListener(MouseEvent.CLICK, Total)
function LeggTil(e:MouseEvent)
{
txtFeil.text =""
pris = listeEkstra.selectedItem.pris
vare = listeEkstra.selectedItem.Vare
stepper1 = Number(stepper.value)
bestilling = listeEkstra.selectedItem
liste.addItem({Vare:vare, Prisris, antall:stepper1})
listeMat.push(bestilling)
}
Details: As you can see i am pushing the values in listeMatEkstra into listeMat. Then after the user has choosen the items he would like to push over to listeMat, I would like to be able to present the user with a overview over the total price (listeMat.pris) pris = price. Including the values that already was in the datagrid
So, this is how i have been trying to to it: (Still frame 1)
Frame 1:
function Total (e:MouseEvent){
for (var teller:int = 0;teller<listeMat.length;teller++){
sum = sum + listeMat.Pris[teller]
}
txtFeil.appendText("Total = " + sum) //textfield on the next frame
nextFrame();
}
This is the error i constantly is getting:
TypeError: Error #1010: A term is undefined and has no properties. at Honningogmelk_fla::MainTimeline/Total()
Help, it would save my entire month!
-
Client Software Programmer
throw it all in a variable in the first frame when its done and than on the second from textfield = root.variable_name;
-
.
Hi,
That didnt really help with the error Alloy, the error was due to something not being/no value when button pressed
and the code needed a fair bit more than just declating a var.
In AS3 you must declare a number as String(number) or number.toString() when used in a textField.
Somewhat confusing as you left out some functions and we needed to add all the steppers and slider and datagrids to make this happen, next time post your *.fa.
I just made up some vars as they were not there, they must be similar though.
PHP Code:
import flash.events.MouseEvent;
stop();
var sum:Number = 0; var sliderValue:Number = 20; var j:Number; var i:Number;
var listeMat:Array = new Array();
listeMat[0] = {Vare:"Gulasjsuppe",Pris:20,antall:(sliderValue / 2).toFixed(0)}; listeMat[1] = {Vare:"Potetlefser",Pris:15,antall:(sliderValue / 2).toFixed(0)}; listeMat[2] = {Vare:"Laks",Pris:30,antall:(sliderValue / 2).toFixed(0)}; listeMat[3] = {Vare:"Cottage Cheese",Pris:10,antall:(sliderValue / 2).toFixed(0)}; listeMat[4] = {Vare:"Blåbærpai",Pris:25,antall:(sliderValue / 2).toFixed(0)}; listeMat[5] = {Vare:"Kantarellsuppe",Pris:35,antall:(sliderValue / 2).toFixed(0)}; listeMat[6] = {Vare:"Brød",Pris:7,antall:(sliderValue / 2).toFixed(0)}; listeMat[7] = {Vare:"Kvarg",Pris:17,antall:(sliderValue / 2).toFixed(0)}; listeMat[8] = {Vare:"Salat",Pris:32,antall:(sliderValue / 2).toFixed(0)};
for (j = 0; j < listeMat.length; j++) { liste.addItem(listeMat[j]); } // *** Traces trace("listeMat length: " + listeMat.length); trace("listeMat[0].Vare: " + listeMat[0].Vare); trace("listeMat[0].Pris: " + listeMat[0].Pris); trace("listeMat[0].antall: " + listeMat[0].antall);
var listeMatEkstra:Array = new Array();
listeMatEkstra[0] = {Vare:"Multeiskrem",Pris:35}; listeMatEkstra[1] = {Vare:"Aioli",Pris:5}; listeMatEkstra[2] = {Vare:"Granola",Pris:15}; listeMatEkstra[3] = {Vare:"Gresskarkake",Pris:20}; listeMatEkstra[4] = {Vare:"Fruktfat",Pris:50}; listeMatEkstra[5] = {Vare:"Ørret",Pris:40};
for (j = 0; j < listeMatEkstra.length; j++) { listeEkstra.addItem(listeMatEkstra[j]); }
// *** Traces; trace("listeMatEkstra length: " + listeMatEkstra.length); trace("listeMatEkstra[0].Vare: " + listeMatEkstra[0].Vare); trace("listeMatEkstra[0].Pris: " + listeMatEkstra[0].Pris);
btnLeggTil.addEventListener(MouseEvent.CLICK, LeggTil); btnSlett.addEventListener(MouseEvent.CLICK, Slett); btnTotal.addEventListener(MouseEvent.CLICK, Total);
function LeggTil(e:MouseEvent):void { if (listeEkstra.selectedItem) { txtFeil.text = "";
stepper1.value = Number(stepper.value);
var vare:String = listeEkstra.selectedItem.Vare; var pris:Number = listeEkstra.selectedItem.Pris; var anta:Number = stepper1.value;
var addedItem:Object = {Vare:vare,Pris:pris,antall:anta}; liste.addItem(addedItem);
listeMat.push(addedItem); } }
function Slett(e:MouseEvent):void {
}
function Total(e:MouseEvent):void { sum = 0; trace(listeMat.length); for (i = 0; i < listeMat.length; i++) { sum += listeMat[i].Pris; trace(listeMat[i].Pris); } txtFeil.appendText("Total = " + String(sum) + "\n"); //textfield on the next frame; //nextFrame(); // if you need to go next frame }
and Frame2 if you really really need it, txt.text = String(sum);
Last edited by fruitbeard; 06-16-2015 at 08:53 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|