Copy link to clipboard
Copied
i have a couple functions that i need to activate randomly one after the other
can ANYONE help or point me in the right dirrection?
this is for a school project and my teacher is really bad and googles everything and just tells us the lesson after 😕
Copy link to clipboard
Copied
Show your functions and explain what you are having a problem with
Copy link to clipboard
Copied
okay so this is my code for my game that counts up the score every time you click on each positive button, but counts down when you click on the negative buttons.
what i would like to do is to show the POSITIVE button at random instead of using the time line to show the positive scoring button in different places on the stage.
i thought maybe making some more positive buttons, making them not visible then running a new function, so one of the positive buttons would show when one function is called at random?
var score: Number;
//event listeners to increase the score when specific event when cued
btnPos1.addEventListener(MouseEvent.CLICK, on_press);
//event listeners to decrease the score when specific event when cued
btnNeg1.addEventListener(MouseEvent.CLICK, on_press2);
btnNeg2.addEventListener(MouseEvent.CLICK, on_press2);
btnNeg3.addEventListener(MouseEvent.CLICK, on_press2);
btnNeg4.addEventListener(MouseEvent.CLICK, on_press2);
//sets the score to 0
function init():void
{
score = 0;
scoreWindow.text = score.toString();
}
//updates the score
//removes all positive scoring buttons as only one can be pressed at a time
function on_press(event:MouseEvent):void
{
updateScore();
btnPos1.visible = false
}
//increases the score by 5
function updateScore():void
{
score += 5;
scoreWindow.text = score.toString();
}
//updates the score
function on_press2(event:MouseEvent):void
{
updateScore2();
}
//decreases the score by 10
function updateScore2():void
{
score -= 10;
scoreWindow.text = score.toString();
}
init();
Copy link to clipboard
Copied
You do not need to have mutliple buttons to do the same thing along a timeline. You can use one button and set its visible property to true/false as desired.
If there is some random aspect to making it appear, then you need to define controls for making it happen randomly. Generally, the key to any random processing invvolves making use of the Math.random() function.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now