scopa
April 13, 2006, 6:33pm
1
Hey all, I have another issue…
Basically I have 14 text boxes, each box draws its content from an external txt file. Next to each text box is a button. I want the button to be either visible=true or visible=false depending on weather or not the text box has content or is “undefined” Here is what I have so far, and it’s not working:
loadText = new LoadVars();
loadText.load(cat1+"_"+cat2+"_"+cat3+"_"+cat4+"_products.txt");
loadText.onLoad = function() {
product1.text = this.product1;
product2.text = this.product2;
product3.text = this.product3;
product4.text = this.product4;
product5.text = this.product5;
product6.text = this.product6;
product7.text = this.product7;
product8.text = this.product8;
product9.text = this.product9;
product10.text = this.product10;
product11.text = this.product11;
product12.text = this.product12;
product13.text = this.product13;
product14.text = this.product14;
};
for (x=1, x<14, x++){
if (this.product+x == undefined) {
this.send+x+_btn._visible = false;
} else {
this.send+x+_btn._visble = true;
}
}
So as you can see, I would like a FOR loop to just run through the variables and check to see if any of them are undefined. if it is, then make the correct send button invisible.
any ideas?
scopa
April 13, 2006, 6:39pm
2
Oh ya, once this is solved, I have basically the same issue in another section. Basically, if an image is undefined, I want the button to be invisible.
for (x=1; x<14; x++){
if (this["product"+x] == undefined) {
this["send"+x+"_btn"]._visible = false;
} else {
this["send"+x+"_btn"]._visible = true;
}
}
scopa
April 13, 2006, 6:56pm
4
matthewjumps:
ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#0000FF]for[/COLOR] [COLOR=#000000]([/COLOR]x=[COLOR=#000080]1[/COLOR]; x<[COLOR=#000080]14[/COLOR]; x++[COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000FF]this[/COLOR][COLOR=#000000][[/COLOR][COLOR=#FF0000]“product”[/COLOR]+x[COLOR=#000000]][/COLOR] == [COLOR=#0000FF]undefined[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]this[/COLOR][COLOR=#000000][[/COLOR][COLOR=#FF0000]“send”[/COLOR]+x+[COLOR=#FF0000]“_btn”[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000FF]_visible[/COLOR] = [COLOR=#000000]false [/COLOR];
[COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]this[/COLOR][COLOR=#000000][[/COLOR][COLOR=#FF0000]“send”[/COLOR]+x+[COLOR=#FF0000]“_btn”[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000FF]_visible[/COLOR] = [COLOR=#000000]true [/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[/LEFT]
[/FONT]
hmm, I just tried that, and I got some errors:
**Error** Symbol=slider, layer=Layer 3, frame=1:Line 19: ';' expected
for (x=1, x<14, x++){
**Error** Symbol=slider, layer=Layer 3, frame=1:Line 20: ';' expected
if (this["product"+x] == undefined) {
**Error** Symbol=slider, layer=Layer 3, frame=1:Line 22: 'else' encountered without matching 'if'
} else {
**Error** Symbol=slider, layer=Layer 3, frame=1:Line 25: Unexpected '}' encountered
}
Total ActionScript Errors: 4 Reported Errors: 4
any ideas?
no you tried the wrong thing…note the error for (x=1, x<14, x++){
it should be for (x=1**[COLOR=“Red”];[/COLOR]** x<14**[COLOR=“Red”];[/COLOR]** x++){
recopy the AS i posted above…
scopa
April 13, 2006, 7:25pm
6
well, that stopped the errors, but the script isn’t working correctly.
For testing purposes, I made the product2 variable in the text file undefined.
The flash movie shows “undefined” in the product2 text box… but the send2_btn is still there.
I think I need to also add a line that says “if the product box is undefined, dont show the product box or the send button” like:
if (this["product"+x] == undefined) {
this["product"+x]._visible = false;
this["send"+x+"_btn"]._visible = false;
}
but that doesn’t work either… ugh… what am I doing wrong?
scopa
April 13, 2006, 8:04pm
7
so I thought that maybe I needed to define another variable in the loop for it to work… but its still not working correctly. Basically the loop is either making everything invisible, or everything visible. I can’t get it to find the undefined element and hide only the correct objects.
for (x=1; x<14; x++){
var definer = this["product"+x].text;
if (definer == undefined) {
this["product"+x]._visible = false;
this["send"+x+"_btn"]._visible = false;
} else {
this["product"+x]._visible = true;
this["send"+x+"_btn"]._visible = true;
}
}
var loadText:LoadVars = new LoadVars();
loadText.load(cat1 + "_" + cat2 + "_" + cat3 + "_" + cat4 + "_products.txt");
loadText.onLoad = mx.utils.Delegate.create(this, function () {
for (var x:Number = 1; x < 14; x++) {
this["product" + x].text = this.loadText["product" + x];
if (this.loadText["product" + x] == undefined) {
this["send" + x + "_btn"]._visible = false;
} else {
this["send" + x + "_btn"]._visible = true;
}
}
});
Should work if you are using AS2
scopa
April 14, 2006, 6:16pm
9
TheCanadian:
ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#000000]**var**[/COLOR] loadText:[COLOR=#0000FF]LoadVars[/COLOR] = [COLOR=#000000]**new**[/COLOR] [COLOR=#0000FF]LoadVars[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
loadText.[COLOR=#0000FF]load[/COLOR][COLOR=#000000]([/COLOR]cat1 + [COLOR=#FF0000]““[/COLOR] + cat2 + [COLOR=#FF0000]” ”[/COLOR] + cat3 + [COLOR=#FF0000]“_”[/COLOR] + cat4 + [COLOR=#FF0000]“_products.txt”[/COLOR][COLOR=#000000])[/COLOR];
loadText.[COLOR=#0000FF]onLoad[/COLOR] = mx.[COLOR=#000080]utils[/COLOR].[COLOR=#000080]Delegate[/COLOR].[COLOR=#000080]create[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]this[/COLOR], [COLOR=#000000]function [/COLOR] COLOR=#000000 [/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000]var [/COLOR] x:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#000080]1[/COLOR]; x < [COLOR=#000080]14[/COLOR]; x++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]this[/COLOR][COLOR=#000000][[/COLOR][COLOR=#FF0000]“product”[/COLOR] + x[COLOR=#000000]][/COLOR].[COLOR=#0000FF]text[/COLOR] = [COLOR=#0000FF]this[/COLOR].[COLOR=#000080]loadText[/COLOR][COLOR=#000000][[/COLOR][COLOR=#FF0000]“product”[/COLOR] + x[COLOR=#000000]][/COLOR];
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000FF]this[/COLOR].[COLOR=#000080]loadText[/COLOR][COLOR=#000000][[/COLOR][COLOR=#FF0000]“product”[/COLOR] + x[COLOR=#000000]][/COLOR] == [COLOR=#0000FF]undefined[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]this[/COLOR][COLOR=#000000][[/COLOR][COLOR=#FF0000]“send”[/COLOR] + x + [COLOR=#FF0000]“_btn”[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000FF]_visible[/COLOR] = [COLOR=#000000]false [/COLOR];
[COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]this[/COLOR][COLOR=#000000][[/COLOR][COLOR=#FF0000]“send”[/COLOR] + x + [COLOR=#FF0000]“_btn”[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000FF]_visible[/COLOR] = [COLOR=#000000]true [/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];
[/LEFT]
[/FONT]
Should work if you are using AS2
Excellent! That worked well! I just had to add a " this[“product” + x].text = " “;” so the “undefined” wouldn’t display.
Thanks a lot!