Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Alpha using Variable 3

Status
Not open for further replies.

tomhughes

Vendor
Aug 8, 2001
233
US
I am trying to set the alpha value of a MC according to the value of a variable.
The variable is in the form strVar(i).
If the variable matches a set value, then set the alpha to 50%, otherwise set it to 0%.
Here is the code I am using, but it always sets the value of x to 1, indicating that the first if statement is always true, when in fact it is not.
Does anyone have any ideas how to correct this?



onClipEvent (load) {
for (i=1; i<=strVar0; i++) {
if ([&quot;strVar&quot;+i] == &quot;Facilities Design&quot;) {
x = 1;
}
}
if (x=1) {
this._alpha = 50;
} else {
this._alpha = 0;
}
}
 
Outside of this bit of script, what is being done with
Code:
strVar0
? frozenpeas
 
strVar(i) is the format for variables that have been received from a data base query. The number of variables returned from the data base is determined by the number of matches of the query. The variables are all contained in text boxes in the main timeline.
strVar0 is different from the rest of the variables, since it contains the number of records returned, and not a particular value of a match.
This part of the code is working properly, since I can see the variables in the text boxes.
 
I changed the if statement to if(x==1). Now it always sets the alpha to 0%, whether or not there is a match.
 
The if (x==1) statement is right, thus your condition must never be true.
I've you tried a trace action on x in your loop to see if it's value is ever set to 1? Regards,

oldman3.gif
 
dont see why the code is failing but try this

onClipEvent (load) {
number =0;
for (i=1; i<=strVar0; i++) {
if ([&quot;strVar&quot;+i] == &quot;Facilities Design&quot;) {
number=1; }
}
setalpha(number);
}


function setalpha(number){
if(number==1){
mcname._alpha=50;
}
if(number==0){
mcname._alpha=0;
}
}
}
 
No, but if you give me your email, I can send it to you.
 
Bill - I am working on the code you sent. One problem I found is in the for loop.

for (i=1; i<=strVar0; i++)

The program didn't recognize strVar0. I am going to try _Level0.strVar0.

I have been putting hard values in the place of strVar0 - To be specific, I have been putting the value 4 in its place.

I have also been trying a while loop instead of a for loop.However I have found that when no data is returned from the data base( I can look in the text box and see no data); the value returned in neither &quot;&quot; nor null. I don't understand what value it would be.
 

This line is not eveluating properly

[&quot;strVar&quot;+i] == &quot;Facilities Design&quot;

I have also tried

[&quot;_Level0.strVar&quot;+i] == &quot;Facilities Design&quot;

Any ideas ??
 
Did you try:

Code:
[strVar+i] == &quot;Facilities Design&quot;
frozenpeas
 
It should be:

_level0[&quot;strVar&quot;+i] == &quot;Facilities Design&quot;

Or...

_root[&quot;strVar&quot;+i] == &quot;Facilities Design&quot;


Here's what I did.

On the first frame of my movie, i defined the following:

strVar1 = &quot;test1&quot;;
strVar2 = &quot;test2&quot;;
strVar3 = &quot;test3&quot;;
strVar4 = &quot;Facilities Design&quot;;
strVar5 = &quot;test5&quot;;
strVar6 = &quot;test6&quot;;
stop();

Then on the movie clip, this code with trace actions:

onClipEvent (load) {
for (i=1; i<=6; i++) {
trace(_root[&quot;strVar&quot;+i]);
if (_root[&quot;strVar&quot;+i] == &quot;Facilities Design&quot;) {
x = 1;
}
}
if (x==1) {
this._alpha = 50;
trace(&quot;ALPHA = 50&quot;);
} else {
trace(&quot;ALPHA = 0&quot;);
this._alpha = 0;
}
}
Regards,

oldman3.gif
 
I appreciate all the help everyone has given me on this.

Can you direct me to some more informatoin on the following.

1) What is the difference between _Level0, and _Root?

2) What is the proper use of brackets as in
[&quot;strVar&quot; + i]?

3) Does the debugger in IE 5.5 use Active X ? Due to security reasons, our company has turned off Active x capabilities of our Browser?
 
1- _root is the main level (or the root level) of any given movie. In any individual movie, you can also refer to the root level by using _level0, it would be the equivalent of _root. There's only a difference when loading external .swfs in your main movie on other levels. Thus if you have a loaded movie on level 1 (or any other level) of your main movie, and from this loaded movie you want to target the main movie's timeline, you would necessarily have to use _level0, because if you used _root in that case, you would be targeting the _root level of that loaded movie itself rather than the main movie's timeline, in which this extaernal movie is loaded. Any clearer?

2- This is called &quot;associative array syntax&quot;. You can use...

_level0[&quot;strVar&quot;+i] == &quot;Facilities Design&quot;
_level5[&quot;strVar&quot;+i] == &quot;Facilities Design&quot;
_root[&quot;strVar&quot;+i] == &quot;Facilities Design&quot;

Or even this is some cases...
_this[&quot;strVar&quot;+i] == &quot;Facilities Design&quot;

3- Sorry don't know the answer to that!You can win them all!

Regards,

oldman3.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top