A Flash Developer Resource Site

1. Making multiple items invisible

Hi guys sorry if this is a simple question, but I've been trying to do this all day! So far I've been lucky and managed to find examples of everything else I've tried to do.

Im making a game where you can modify a car, one of the options is to add different sets of wheels. I have 30 different wheels and I want to hide all the wheels apart from the ones the user has selected. I know I could do it like this:

function wheel1(event:MouseEvent):void {
wheel1a.visible=true;
wheel2a.visible=false;
wheel3a.visible=false;
wheel4a.visible=false;
wheel5a.visible=false;
wheel6a.visible=false;

etc etc....

But there must be a simpler way, as it will take ages to do this for all 30 wheels. Can anyone shed any light on this or point me in the right direction please? I've been looking at else and if statements but cant seem to come up with anything that works.

Thanks Steve

2. first you need to know Array
It's a way to save a huge amount of similar of same thing,and handle them easily.

step1
var i:int=0
var numArray:Array=new Array(0,0,0,0,0)
numArray[1]+=1
numArray[2]+=2
numArray[3]+=3
trace(numArray[0])
trace(numArray[1])
trace(numArray[2])
trace(numArray[3])

step2
var i:int=0
var numArray:Array=new Array(0,0,0,0,0)

for(i=0;i<5;i++){
numArray[i]+=a
trace(numArray[i])
}

and before step3,you should know one more thing about Array

var numArray:Array=new Array(0,0,0,0)

equals

var numArray:Array=[]
numArray.push(0,0,0,0)

equals

var numArray:Array=[]
numArray[0]=0
numArray[1]=0
numArray[2]=0
numArray[3]=0

wheelArray.length in step3 depends on how many things you push in the array

step3
var i:int=0
var wheelArray:Array=[]

wheelArray.push(wheel1a,wheel2a,wheel3a,wheel4a)

for(i=1;i<wheelArray.length;i++){
wheelArray[i].visible=false
trace(i+':'wheelArray[i].visible)
}

and step4,which I don't suggest you to do at the moment,once you are familar with array,you can try this
forEach

step4
var i:int=0
var wheelArray:Array=[]

wheelArray.push(wheel1a,wheel2a,wheel3a,wheel4a)

wheelArray.forEach(afunction)
function afunction(a,aa,arr){
if(aa==0){
trace(aa+':'a[aa].visible)
return
}
a.visible=false
trace(aa+':'a[aa].visible)
return
}

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap