# Array Code Question

**URL:** https://forum.kirupa.com/t/array-code-question/31106
**Category:** flash
**Created:** [September 18, 2003, 7:12am UTC](https://forum.kirupa.com/t/array-code-question/31106 "2003-09-18T07:12:29Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![forjulia](https://avatars.discourse-cdn.com/v4/letter/f/5e9695/32.png) [@forjulia](https://forum.kirupa.com/u/forjulia)
#### Post date: [September 18, 2003, 7:12am UTC](https://forum.kirupa.com/t/array-code-question/31106/1 "2003-09-18T07:12:29Z")

</div>

Hello,

I’m trying to display one of buttons from the array randomly to the screen when the ‘space bar’ is pressed in the according square.  
I have a feeling it could be something to do with the parent class but not sure.  
My current code shown below navigates a character around the area and performs a hit test when in a correct square. Thanks for help

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 &gt; 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&lt;l;i++) if (obstacles*.hitTest(_x,_y,true)){_x = prevx; break;}
_y = Math.min(Math.max(_y+vy*dy, bounds.T), bounds.B)
for(i=0;i&lt;l;i++) if (obstacles*.hitTest(_x,_y,true)){_y = prevy; break;}
if (_currentFrame &gt; 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]   
\_parent.chest.\_visible = false;  
\_parent.boot.\_visible = false;  
\_parent.bones.\_visible = false;  
\_parent.hole.\_visible = false;  
\_parent.fish.\_visible = false;  
\_parent.inst\_bubble.\_visible = false;  
\_parent.quit\_bubble.\_visible = false;

```
//create array of buttons
myButtons = [chest,boot,bones,hole,fish];

```

}

onClipEvent(enterFrame){  
if(this.hitTest("\_root.square1")){  
if(Key.isDown(Key.SPACE)){\_root[myButtons[boot]].\_visible=true;  
//Randomly pick out button from array and display to screen   
myButtons[Math.random(myButtons.length)].\_visible = true;
