You can create a counting integer variable that adds every time it enters the snowflake function and a goal variable to tell the function at which frame number to initiate the code in the function, like this:
Code:
stage.addEventListener(Event.ENTER_FRAME, snowflake);
//init variables
var count:int=0;
var goal:int=int(Math.random()*50+50);//this will give you a number from 50-100
function snowflake(event:Event):void{
if(count>=goal){
count=0;
goal=int(Math.random()*50+50);
//add your code that was initially in your function here
}
}
I believe this would work, there may be an error in the code, have not checked it.
stage.addEventListener(Event.ENTER_FRAME, snowflake);
//init variables
var count:int=0;
var goal:int=int(Math.random()*50+50);
//this will give you a number from 50-100
var _Snowflake:mcSnowflake; //I PUT THIS IN HERE
function snowflake(event:Event):void{
if(count>=goal){
count=0;
goal=int(Math.random()*50+50);
//add your code that was initially in your function here
I am making a game for college and have been trying to get this right for ages.
"snowflake" is actually a coin! I recycled actionscript from another project, so left the name "snowflake" on the coin movie.
Basically the coins, fall from the sky at random and a little character at the bottom moves left and right and tries to catch them. I intend to use a hit test and dynamic text to count the coins he catches and then he flies off to piggy heaven
Sounds easy enough, but have been at it for days now!!
I attached two fla,
in piggy2.fla , i got piggy moving
in the 'lots of coins.fla', I have coins falling every frame instead of every now and then as you would expect in a game
You helped me so well the last time, i have one last question for you about my project, if you could PLEASE help me again.
I've been at it since to no avail though. It wrecking my head!
In the fla (attached) the piggy is on stage and i'm using a hittest for with the random coins which arent on stage, so i think im supposed to use the variable name, but i cant get it to work.
I attached an example zipped fla if you could take a look i'd be very happy
snowflake is a movie clip of a coin falling, Piggy is a pig
Really sorry for bothering you,
This is part of a big an assignment i have to have in for friday and ive hit a brick wall.
Thanks for your help
B
The code i used is as follows in case you dont want to look at the fla:
// initialize arrow variables
var leftArrow:Boolean = false;
var rightArrow:Boolean = false;
var upArrow:Boolean = false;
var downArrow:Boolean = false;
// set event listeners
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyPressedUp);
stage.addEventListener(Event.ENTER_FRAME, moveMascot);
// set arrow variables to true
function keyPressedDown(event:KeyboardEvent) {
if (event.keyCode == 37) {
leftArrow = true;
} else if (event.keyCode == 39) {
rightArrow = true;
}
}
// set arrow variables to false
function keyPressedUp(event:KeyboardEvent) {
if (event.keyCode == 37) {
leftArrow = false;
} else if (event.keyCode == 39) {
rightArrow = false;
}
}
// move every frame
function moveMascot(event:Event) {
var speed:Number = 5;
if (leftArrow) {
piggy_mc.x -= speed;
}
if (rightArrow) {
piggy_mc.x += speed;
}
if (upArrow) {
piggy_mc.y -= speed;
}
if (downArrow) {
piggy_mc.y += speed;
}
}
stage.addEventListener(Event.ENTER_FRAME, snowflake);
var count:int=0;
var goal:int=int(Math.random()*50+50);
function snowflake (event:Event):void
{
count++;
if(count>=goal){
count=0;
var _Snowflake:mcSnowflake;
I really suggest you look over this code, it looks as if your just trying to take examples and put them together. You should learn how this code works and why it works. Also try stuff from scratch, if I'm wrong though I apologize.
What I'm doing here is just adding another if statement to each snowflakes individual EnterFrameFunction event handler function. A simple hitTestObject method works fine in your case.
Please review it and ask questions if you don't understand how this works.
Thanks so much. No you are completely right. I am doing a course in Multimedia and have a flash module, but it doesnt entail much actionscript. The assignment were given was just supposed to be about making something with an "emotional core" like a short animation but we decided to challenge overselves and having invested so much time we cant start again with the deadline looming. I had hit an impasse.
I will reference this post on submission.
Thank you very much for your help, i will study that code and appreciate your offer to answer my questions.