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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Code Question

Status
Not open for further replies.

forjulia

Programmer
Joined
Sep 18, 2003
Messages
1
Location
AU
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 > 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.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.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]
_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(&quot;_root.square1&quot;)){
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;

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 > 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.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.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]
_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(&quot;_root.square1&quot;)){
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;

 
ok....why dont you start again

i have no idea what you are tring to do. could you try and explain it again.

you want a random button to appear when some condition is met is about all i think i have.

are you using mx?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top