I cannot figure out how to make a loop progress fully from the eventEnterFrame
function. It does the entire loop in one frame. I am trying to make it just call the classes function and let it run thru its course. My code is trying to call a function from eventEnterFrame
and then that function will call other functions and do its task.
The task is creating a random Y value, placing a movieClip there and then implementing a gravity function so the movieClip falls. The eventEnterFrame
just calls the create movieClip function via a If loop so it creates multiples and they all fall at different Y locations.
I just want to clean up my eventEnterFrame
function and move code out of the Main. It would not be hard to just do in the Main but I don't want it in the Main. Any help would be greatly appreciated.
private function eventEnterFrame(e:Event):void{
if(i<10){
i++;
} else if(i>=10){
spikeA.name = "spike_"+j;
addChild(spikeA);
j++;
i=0;
}
spikeA.y+=5;
if(spikeA.y>600){
spikeA.y=100;
}
}
This is how I have it just spawning one "spike" in the Main
The second issue is controlling each created "spikeA_"+j and giving each the falling class command, right now it just creates one spikeA and causes it to move downwards.
Thanks
spike code, most has been taken out from me trying a lot of ways to get it to work so it just places it since I got frustrated and did a clean slate
package {
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Stage
import gravity;
public class spike extends MovieClip {
var random1:Number;
public function spike() {
random1 = Math.floor(Math.random()*700)+1;
this.x = random1;
this.y = 50;
if(this.y>600){
this.y=200;
}
}
}
}
First, you need to somehow instantiate a new item in order to spawn it. So somewhere you'll need to use the
new
keyword. If your spike is an item in your library, with export for actionscript checked in it's properties and Class name ofSpike
(for example), you'd probably want to do the following:If you wanted to be more efficient, you could just recycle your spikes instead of spawning new ones and removing them.
Create all your spikes at the start (or if using FlashPro you could drop them all on the timeline inside a container movie clip)
Take out the timer and spawn function from my code above.
Then instead of removing a spike in the enterframe handler, just reset it's y position to whatever you want.