nonprogrammer
04-29-2009, 09:56 PM
The end result should be as follows:
There will be 5 doors and one enemy. The doors will be on the stage, while the enemy will be added to the stage via code. The doors will all have an initial state of being closed. After a small amount of time I will change the state of all those doors to being open. When this state change happens, I want to spawn my single enemy in one of those doors at random. This enemy will then move around the stage (flying) based upon specific paths I set out (multiple paths, one chosen at random) and end their trip by flying back into one of the doors and be removed from the stage, with the doors going back to their closed state.
Rinse and repeat.
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
var doorClosed:Boolean = true
// Create a new Timer object with a delay of 10 seconds
var myTimer:Timer = new Timer(10000);
myTimer.addEventListener("timer", timerFunction);
// Start the timer
myTimer.start();
trace("Doors are closed");
// Function will be called every 10 seconds
function timerFunction(event:TimerEvent)
{
if (doorClosed = true)
{
Door.gotoAndPlay(1);
doorClosed = false;
trace("Doors are open");
}
else
{
Door.gotoAndPlay(2)
doorClosed = true
trace("Doors are closed");
}
}
Now I've got 2 issues with this:
1) Even though all 5 doors were made by dragging out multiple copies of a single movie clip and all of them have the same instance name of "Door", only 1 of them is being affected by the code. What's going on?
2) This one isn't a big deal, but I want to know how to fix it anyway. Watching the file play shows the door changing from green (closed) to blue (open) to green (closed) and so forth just like it is supposed to. The issue is that I don't have the traces properly placed, so it traces "The doors are closed." and then "The doors are open." and then keeps on tracing "The doors are open." every single time, even when they switch to closed.
Any help in making all the code more neat/efficient would also be great.
One more thing, someone else (on another site) told me the following about how to draw the enemy to the screen (and then never clarified or helped again):
5) when the time is as long as you want, or when the doors are open,
_root.createMovieClip("[name]", "[name]", 100);
Then give it x and y coordinates of the locations or equal to the doors. Use "if" statements with a "random(#)" for which door to create it at. Happy to help with that, too.
I'm not actually sure what he was saying to me since I'm new to this.
Any help will be greatly appreciated.
There will be 5 doors and one enemy. The doors will be on the stage, while the enemy will be added to the stage via code. The doors will all have an initial state of being closed. After a small amount of time I will change the state of all those doors to being open. When this state change happens, I want to spawn my single enemy in one of those doors at random. This enemy will then move around the stage (flying) based upon specific paths I set out (multiple paths, one chosen at random) and end their trip by flying back into one of the doors and be removed from the stage, with the doors going back to their closed state.
Rinse and repeat.
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
var doorClosed:Boolean = true
// Create a new Timer object with a delay of 10 seconds
var myTimer:Timer = new Timer(10000);
myTimer.addEventListener("timer", timerFunction);
// Start the timer
myTimer.start();
trace("Doors are closed");
// Function will be called every 10 seconds
function timerFunction(event:TimerEvent)
{
if (doorClosed = true)
{
Door.gotoAndPlay(1);
doorClosed = false;
trace("Doors are open");
}
else
{
Door.gotoAndPlay(2)
doorClosed = true
trace("Doors are closed");
}
}
Now I've got 2 issues with this:
1) Even though all 5 doors were made by dragging out multiple copies of a single movie clip and all of them have the same instance name of "Door", only 1 of them is being affected by the code. What's going on?
2) This one isn't a big deal, but I want to know how to fix it anyway. Watching the file play shows the door changing from green (closed) to blue (open) to green (closed) and so forth just like it is supposed to. The issue is that I don't have the traces properly placed, so it traces "The doors are closed." and then "The doors are open." and then keeps on tracing "The doors are open." every single time, even when they switch to closed.
Any help in making all the code more neat/efficient would also be great.
One more thing, someone else (on another site) told me the following about how to draw the enemy to the screen (and then never clarified or helped again):
5) when the time is as long as you want, or when the doors are open,
_root.createMovieClip("[name]", "[name]", 100);
Then give it x and y coordinates of the locations or equal to the doors. Use "if" statements with a "random(#)" for which door to create it at. Happy to help with that, too.
I'm not actually sure what he was saying to me since I'm new to this.
Any help will be greatly appreciated.