Actionscript variable grouping
- Started
- Last post
- 8 Responses
- Bullitt
Actually learning this now, for real.
Anyone know how I can group some variables to = one value ( basically to save time typeing it out 5 times, because there all going the same place.)example
if(defaultHover = true)
{
speechBubble.gotoAndStop(1);
}
so I want to add a few more variables to this;
obviously I can't write:
if (defaultHover, psychoGiraffe, ratMobile = true)
{
speechBubble.gotoAndStop(1);
}thanks in advance :)
- chrisRG0
will dispatch if any is true:
if (defaultHover || psychoGiraffe || ratMobile)
speechBubble.gotoAndStop(1);will dispatch if all of them are true:
if (defaultHover && psychoGiraffe && ratMobile)
speechBubble.gotoAndStop(1);
- noel0
you even started wrong:
if(defaultHover = true)
must be in your case:
if(defaultHover == true)more of them (all):
if(defaultHover == true && defaultHanger == true && defaultHelper == true)more of them (one of them):
if(defaultHover == true || defaultHanger == true || defaultHelper == true)
- noel0
&& stands for AND
|| stands for OR
- chrisRG0
tip:
if(varName){}... will evalute if var is true
if(!varName){}... will evalute if var is false
- Bullitt0
thanks for the tips guys
- rounce0
If you don't know all your operators, you're gonna be doing thinks cackhanded from the start.
- forbes0
var optionOne: Array = new Array[defaultHover, psychoGiraffe, ratMobile]
var optionTwo:Array = new Array[blah psychoblah, ratblah];if(optionOne == true) {
speechBubble.gotoAndStop(1);
}if(optionTwo == true) {
speechBubble.gotoAndStop(1);
}or something along those lines anyway. group your assets into arrays. that'll cut your code down.
- rounce0
@Forbes: you're only checking for the reservation of an Array object in memory, not it's contents. All of the objects in optionOne might not exist when the Array instance is created, and would throw NullPointerExceptions when you add them to the Array. The Array however would still return true.
Deffo not a kosher method!