Urgent question - actionscript

i’ll start off by saying… i’m pretty new to using actionscript.

i work at a shelving company and i’m making a small program for the secretary there to make calculations and paperwork easier.

the basic idea of what i want the program to do is to…

<li>have the user input a number (the length of a shelf)
<li>select from a list of radio buttons what type of shelf is wanted
<li>select from a checkbox if the shelf is going to be billed to a builder or a customer, with the default being a builder, and checkbox indicating that it will be billed to a customer.
<li>click an “add” button that will add the shelf information to a list - a list made up of many other added shelves.
<li>finally, when finished inputing all the shelves for one job, click a “done” button, which will display the list of shelves that was created, and total price of the job. from there, the user will also be printing that final scene out.

so what i’m thinking is that i need to use some sort of big multi-lined variable that can contain variables in each line…

<li>a var. for the length
<li>a var. for the choosen type
<li>a var. to show whether or not the checkbox is checked
<li>and the big multi-lined variable to that can add each of those variables all on one line

i’m not sure that anything like this even exists.

the only other thing that i thought might work in this situation is a shared object. but i don’t think that a shared object could have more than more than one “line,” if you know what i mean.

any help with this would be greatly appreciated.

matt

all right i’ve done some searching, and i think what i need is an array.

first of all, am i right?

and if i am right, could someone kindly explain how arrays work? i don’t have that much of a grasp on it.

once again, any help would be appreciated. thanks, matt.

i think you’re on the right track with an array. how about an array of objects? that way you can label (rather than number) your elements.

this function will create the shelf object:


function Shelf(len,type,chk){
   this.len = len;
   this.type = type;
   this.chk = chk;
}

so make a movie (name it, ummm, “shelfmaker”) and create some input text fields where the variables are:

  • len
  • type

and make your check box however you choose, it will toggle a boolean (true or false) variable named … you guessed it, chk.

the add button should read something like:


on(release){
   // create the array if it doesn't already exist
   if(!this.shelfList) this.shelfList = [];

   // add a new shelf to the end of the array
   shelfList.push(new Shelf(this.len,this.type,this.chk);

   // clear the text fields
   this.len = "";
   this.type = "";
   this.chk = 0;
}

then to output your data, write some code to iterate through the array and print each name value pair in the object.

something like:


function outputArray(){
   // make a point to shelfList
   var a = _root.shelfmaker.shelfList;
   for(i in a){
      for(j in a*){
         trace(j+" : "+a*[j]);
      }
   }
}

you’ll want to put that data into a variable or something rather than tracing it. use "
" to get a linebreak.

then call the function when you want it:


// assuming you defined the function in _root
on(release){
   _root.outputArray();
}

thanks a lot…

i’ll definately try using that. once i figure it out. :wink:

matt


function outputArray(){
   // make a point to shelfList
   var a = _root.shelfmaker.shelfList;
   for(i in a){
      for(j in a*){
         trace(j+" : "+a*[j]);
      }
   }
}


// assuming you defined the function in _root
on(release){
   _root.outputArray();
}

could you possibly explain to me the those portions a little more? the first of the two is the one that i don’t really understand at all. for instance, where did the i and j come from? unless i’m just missly something completely obvious. which is probably the case. but i also don’t know too much about for statements so that could be part of the problem.

just a little more help if someone would be so kind.

matt

Yeah… I understand for loops, or so I thought until I started seeing for(j in a)… etc…

can you dissect, Supra?

for (j in a) is what Supra explained recently: let’s say you have an array with 5 elements in it. You’ll get 4, 3, 2, 1, 0. Aka all the index of the array. Plus the prototypes you may have declared earlier.

pom :asian: