-
[RESOLVED] "for" loop killing me
Greetings all
I need some fresh eyes to look at this code because no matter how many examples or tutorials or posts I look at, it seems right. Trouble is I'm more into graphics and there are no programmers in my department. ie. WHAT the heck little stupid thing am I doing wrong ?
PHP Code:
_global.medtype1 = "0";
_global.meddisc1 = "";
_global.medtype2 = "0";
_global.meddisc2 = "";
_global.medtype3 = "0";
_global.meddisc3 = "";
_global.medtype4 = "0";
_global.meddisc4 = "";
_global.medtype5 = "0";
_global.meddisc5 = "";
_global.medtype6 = "0";
_global.meddisc6 = "";
_global.medtype7 = "0";
_global.meddisc7 = "";
_global.medtype8 = "0";
_global.meddisc8 = "";
for (var item_counter=1; item_counter<9; item_counter++) {
if (_global.medtype[item_counter] = "0") {
_root.medlist.medgfx[item_counter].medtypeampule._visible = false;
_root.medlist.medgfx[item_counter].medtypepill._visible = false;
_root.medlist.medgfx[item_counter].medtypespoon._visible = false;
}
if (_global.medtype[item_counter] = "1") {
_root.medlist.medgfx[item_counter].medtypeampule._visible = true;
_root.medlist.medgfx[item_counter].medtypepill._visible = false;
_root.medlist.medgfx[item_counter].medtypespoon._visible = false;
}
if (_global.medtype[item_counter] = "2") {
_root.medlist.medgfx[item_counter].medtypeampule._visible = false;
_root.medlist.medgfx[item_counter].medtypepill._visible = true;
_root.medlist.medgfx[item_counter].medtypespoon._visible = false;
}
if (_global.medtype[item_counter] = "3") {
_root.medlist.medgfx[item_counter].medtypeampule._visible = false;
_root.medlist.medgfx[item_counter].medtypepill._visible = false;
_root.medlist.medgfx[item_counter].medtypespoon._visible = true;
}
_root.medlist.medtext[item_counter] = _global.meddisc[item_counter]
}
Nothing hides and every loop seems to see the if statements as true. Mehaps' it's the way I'm addressing the objects.
<sigh> Thanks to any one who can whack me over the head with the right answer.
Last edited by DarkWisdom; 09-06-2007 at 09:16 AM.
Reason: Code edited
Simply not, those bodies must have been dumped on my front lawn and what blood soaked axe under my bed are you talking about??
-
In all the if statements, change the "=" to "==".
A single equal sign is for assignment, double is for comparision.
Code:
if (_global.medtype[item_counter] == "0") {
-
When in doubt ask
<signature removed by admin>
-
Ok that's a stepforward....
Now I've changed the code to the following :
PHP Code:
_global.medtype1 = "0";
_global.meddisc1 = "";
_global.medtype2 = "0";
_global.meddisc2 = "";
_global.medtype3 = "0";
_global.meddisc3 = "";
_global.medtype4 = "0";
_global.meddisc4 = "";
_global.medtype5 = "0";
_global.meddisc5 = "";
_global.medtype6 = "0";
_global.meddisc6 = "";
_global.medtype7 = "0";
_global.meddisc7 = "";
_global.medtype8 = "0";
_global.meddisc8 = "";
for (var item_counter=1; item_counter<9; item_counter++) {
medtypechecker = _global.medtype[item_counter];
if (medtypechecker == "0") {
this.medlist.medgfx[item_counter].medtypeampule._visible = false;
this.medlist.medgfx[item_counter].medtypepill._visible = false;
this.medlist.medgfx[item_counter].medtypespoon._visible = false;
}
if (medtypechecker == "1") {
_root.medlist.medgfx[item_counter].medtypeampule._visible = true;
_root.medlist.medgfx[item_counter].medtypepill._visible = false;
_root.medlist.medgfx[item_counter].medtypespoon._visible = false;
}
if (medtypechecker == "2") {
_root.medlist.medgfx[item_counter].medtypeampule._visible = false;
_root.medlist.medgfx[item_counter].medtypepill._visible = true;
_root.medlist.medgfx[item_counter].medtypespoon._visible = false;
}
if (medtypechecker == "3") {
_root.medlist.medgfx[item_counter].medtypeampule._visible = false;
_root.medlist.medgfx[item_counter].medtypepill._visible = false;
_root.medlist.medgfx[item_counter].medtypespoon._visible = true;
}
_root.medlist.medtext[item_counter] = _global.meddisc[item_counter]
}
The interesting thing is that the variable "medtypechecker" stays undefined. I see many examples using the [item_counter] variable to define a variable name. The code now jumps from one "if" to the next treating them all as false.
Last edited by DarkWisdom; 09-06-2007 at 10:09 AM.
Reason: Edited code again
Simply not, those bodies must have been dumped on my front lawn and what blood soaked axe under my bed are you talking about??
-
I have even tried to set "medtypechecker" as a global and to "0" but as soon as the code :
medtypechecker = _global.medtype[item_counter];
runs, it becomes undefined. believe me, I'm not just waiting for an answer, but I do run out of ideas for direction.
Simply not, those bodies must have been dumped on my front lawn and what blood soaked axe under my bed are you talking about??
-
Code:
medtypechecker = _global["medtype"+item_counter];
-
Senior Member
medtypechecker = _global.medtype[item_counter];
The line above is looking for an ARRAY called "medtype", then the value of the array at index "item_counter".
You do not have an array defined anywhere.
Instead you have simple variables like
medtype1
medtype2
etc...
The way the above code is written, there is also a LOT of code for very little being done.
Instead of fixing up what you have written, do you mind me asking you what you are trying to do? That way we could maybe supply some example code that would make your life easier.
-
Firstly, dawsonk, Thanks. <grin> You keep steering me in the right direction.
Then, Alluvian, uuhhh well. This is an educational medical situation builder. I'm building up a list of medicine they have in a chronic pain clinic in a certain situation. The reason for all the variables is to be able to build many scenarios with as little work later as possible. I figure that if this endeavor is successful then I could move this over to reading the variables from a text file that the "not-very-computer-literate" lecturers can just edit. I built a multi-choice question that also reads from variables. Even the parients details (age, gender, trouble etc.) are dumped into text fields.
... sorry, rambling a bit. I want to hide the images of the medicine that it isn't ie. pills, liquid or injection (and perhaps more later) Then the person can click on an icon on the top to see which medicines are avaliable to them at any point in the "simulation"
That's about it ....
Simply not, those bodies must have been dumped on my front lawn and what blood soaked axe under my bed are you talking about??
-
The answer ... it seems.
Ok ... thanks, (I'm sure I'll be back) but the array that you pointed out seemed to be the culprate. The help files don't really show how to handle any thing but arrays it seems. The following code worked for me, for any one else in the future looking for this type of answer :
PHP Code:
_global.medtype1 = "0";
_global.meddisc1 = "";
_global.medtype2 = "1";
_global.meddisc2 = "";
_global.medtype3 = "2";
_global.meddisc3 = "";
_global.medtype4 = "3";
_global.meddisc4 = "";
_global.medtype5 = "0";
_global.meddisc5 = "";
_global.medtype6 = "0";
_global.meddisc6 = "";
_global.medtype7 = "0";
_global.meddisc7 = "";
_global.medtype8 = "0";
_global.meddisc8 = "";
for (var item_counter:Number=1; item_counter<9; item_counter++) {
medtypechecker = _global["medtype"+item_counter];
if (medtypechecker == "0") {
this.medlist["medgfx"+item_counter].medtypeampule._visible = false;
this.medlist["medgfx"+item_counter].medtypepill._visible = false;
this.medlist["medgfx"+item_counter].medtypespoon._visible = false;
}
if (medtypechecker == "1") {
this.medlist["medgfx"+item_counter].medtypeampule._visible = true;
this.medlist["medgfx"+item_counter].medtypepill._visible = false;
this.medlist["medgfx"+item_counter].medtypespoon._visible = false;
}
if (medtypechecker == "2") {
this.medlist["medgfx"+item_counter].medtypeampule._visible = false;
this.medlist["medgfx"+item_counter].medtypepill._visible = true;
this.medlist["medgfx"+item_counter].medtypespoon._visible = false;
}
if (medtypechecker == "3") {
this.medlist["medgfx"+item_counter].medtypeampule._visible = false;
this.medlist["medgfx"+item_counter].medtypepill._visible = false;
this.medlist["medgfx"+item_counter].medtypespoon._visible = true;
}
_root.medlist.medtext[item_counter] = _global.meddisc[item_counter]
}
Simply not, those bodies must have been dumped on my front lawn and what blood soaked axe under my bed are you talking about??
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
|