PDA

View Full Version : Array Question



forjulia
September 17th, 2003, 09:24 PM
Hi I need some help please,

I want to create an array of buttons, the buttons are called popupone, popuptwo, popupthree etc.

When the scene is loaded these buttons visibility is set to false so they are invisible. I want to be able to randomly pick one of these buttons from the array and display it to the screen _visible = true.

I知 really not sure how to go about this and really would appreciate some help.

claudio
September 17th, 2003, 11:02 PM
How are you going to pick a random button?

forjulia
September 18th, 2003, 07:36 AM
Hi I was hoping someone could help me,
I知 currently creating an array of buttons and trying to turn the buttons invisible using a for loop. I have then created a function that pulls out a random button and displays it to the screen. This function is then called on a hit test and when the space bar is pressed.

The problem I知 having is turning the buttons to false, I think it may be a problem with the _parent referencing but not sure as I did get an example working in a blank file without using onClipEvent() and the character walking code at the top shown below.

If anyone knows where I知 going wrong can you please help.

Thankyou


onClipEvent(enterFrame){
dx = Key.isDown(Key.RIGHT)-Key.isDown(Key.LEFT)
dy = Key.isDown(Key.DOWN)-Key.isDown(Key.UP)

if (d=(dy*3)+dx) gotoAndStop(d+15)
else if (_currentFrame > 10) gotoAndStop(_currentFrame-10)

prevx=_x; prevy=_y
l = obstacles.length
_x = Math.min(Math.max(_x+vx*dx, bounds.L), bounds.R)
for(i=0;i<l;i++) if (obstacles[i].hitTest(_x,_y,true)){_x = prevx; break;}
_y = Math.min(Math.max(_y+vy*dy, bounds.T), bounds.B)
for(i=0;i<l;i++) if (obstacles[i].hitTest(_x,_y,true)){_y = prevy; break;}
if (_currentFrame > 10 && _x == prevx && _y == prevy) gotoAndStop(_currentFrame-10)
}


onClipEvent(load){
vy = vx = 8
bounds = {L:0,R:1012,T:0,B:767}
obstacles = [_parent.clip1, _parent.clip2, _parent.clip3]
}

onClipEvent(enterFrame){

myButtons = new Array;
myButtons = [bones,chest,boot,fish];


// hide them all
for (index in myButtons) {
myButtons[index]._visible = false;
}



function pickRandom() {
this[myButtons[random(myButtons.length)]]._visible = true;//make a random button visible
}

}


onClipEvent(enterFrame){
if(this.hitTest("_root.square1")){
if(Key.isDown(Key.SPACE)){_root[myButtons[boot]]._visible=true;
pickRandom();
}
}
}

kode
September 18th, 2003, 08:13 AM
I merged the threads you posted in this section of the forum and deleted the thread posted in the Flash MX section. :sigh: