I want to add different objects to a background each time one presses a button. I want it to happen, one at a time. - There will be several buttons ordering to do so.
Should i make different movieclips for each objects?
Can anyone help with some code example
What sort of objects? Will they just be random objects, or things you've already created?
Are you thinking of something like:
Click1: Sky pops up
Click2: grass pops up
Click3: tree pops up
Click4: people pop up
Something like that? If so, I suggest you do it with movieclips. There are several ways to do it from there. Whether you're more comfortable jumping to a frame where those elements exist, or if you'd rather have them set to 0% alpha (transparent) and then have it jump up to 100% when you click a button. Or you could just place them with AS.
So basically you have a bunch of invisible movieclips in the background that the user cant see and as the user clicks one of seven buttons, the corresponding movieclip will appear?
Well start by making each section of the background a seperate movieclip. Click on the movieclip once on the stage and at the bottom, change the 'alpha' to 0% so that it is invisible.
Make sure you give each movieclip a seperate instance name, click on the movieclip once and at the bottom left you will see a text field where you can type in the instance name. Give it something like 'movieclip1' and 'movieclip2' etc etc.
Now make your buttons that will correspond with each of the movieclips. For example, your first button will make the top left movieclip appear (movieclip1) and such. Place the following code on the button by clicking on it once and opening up the actions panel F9:
code:
on (release){
_root.movieclip1._alpha = 100;
}
Make the rest of your buttons and place the same code in them only changing the movieclip1 to the correct name of the corresponding movieclips.
Now when you run it you will only be able to see the buttons and as you click them one at a time, the background will begin to appear
Im not 100% sure thats what your asking, but thats what I understood from your description, so hopefully this will steer you in the right direction.
Yes i want them to pop one after the other. And yes i thought doing it with separate movieclips.
But suppose i have 5 buttons and 100 movieclips. One button will tell, add "one" movieclip. I want background chaos after one makes alot of cliking - making the background full of objects.
Want it random so each time a persons navigates the site, the sequence its different
The reason why they're not invisible is because they're text fields. If you change the text fields to objects such as a square, you will see that it becomes invisible when the movie loads.
Do you plan on having the movieclips be numbers in the end, or was the for test purposes and we're planning on using pictures.
I don´t understand what you mean! - They´re invisible!
Anyway, i tried your suggestion and turned them into shapes. - They´re still invisible after pressing the button.
Maybe the problem is, my frames disposition??
When I ran it, the numbers were visible when the movie was loaded.
As for what you want, you want them to become visible after clicking the button, can you please repost the fla with the shapes so that it'll work here on my computer?
First of all, I dont see the need for the second frame at the moment so I took that out.
Click the button in my attached fla and it'll make the pictures appear. I simply used the same for loop in your first frame and changed the number 0 to 100.
Now what exactly do you mean by having several buttons excuting the order, Im still not sure what that is.
About the buttons:
Imagine a 5 buttons menu, with submenus. Each time i release a button (either menu or submenu) a new object is added to the background.
So basically you have a bunch of movieclips all invisible. As you click one of the buttons, the corresponding movieclip will appear in the background and as you continue to click the other buttons, their corresponding movieclips will appear in the background as well.
Sort of 'remembering' where the user clicked.
Well thats pretty simple. Do what you did here by having all the movieclips invisible. And when you make a button simply put in its actions:
code:
on (release){
_root.pictureMovieclip._alpha = 100;
}
And that will make the movieclip appear.
As for the fla I sent, I was using Flash 8 but I did save it as Flash MX. I'll try again and then reattach it
Thanks for fast respose but.. sorry mate thats not what i want!!!!
I want.. when one presses any button to make appear a random object.
When pressing again - either the same button or other - to add another random object, and so on...
Couldn´t open last your last post attached file either
You must using an older version then MX , so thats why its not opening up.
Anyways, ok let me try once again to wrap my head around what your asking. You have a bunch of movieclips all invisible as well as a bunch of buttons. When you click on one of these buttons, one of the movieclips will appear (alpha = 100)
But what this movieclip shows is completly random?
Ok, if thats the case then this is what you do. Make your movieclip and inside of it start by putting a stop(); action on the first frame. Now on the first frame place a picture of what the movieclip will look like.
Now click on the second frame and put a different picture it could be. Then do it to the third frame and continue to do so however many times you like. Give the movieclip an instance name as well, lets call is myMovieclip here
Now make your button and place the following code:
code:
on (release) {
_root.myMovieclip.gotoAndStop(random(5)+1);
}
So basically when you click on the button, the movieclip goes to and stops on a frame. The frame is decided by a random number between 1 and 5 (in this case). Change the 5 to the number of frames you decided to use
I hope you understand, and hopefully thats what your asking
Example:
I have 2 buttons, and 100 images that i want to appear in the background each time one clik appens.
When i release b1 - a random object is added to the background.
If i release b1 again - another object is added
If i release b2 - another object is added
....... and it goes on and on - till i have no more objects to fill the background
Another thing - Im using MX -
Thanks again - hope you have understood my quest now
Ok, so when you click any button , one of the one hundred movieclips invisible on the background will appear , but its random
So for example you click the first button and it randomly decides to show the 43rd movieclip , is that right?
Ok , well start by making your 100 movieclips and have them invisible when the movie loads. Now on your buttons place the following code:
code:
on (release) {
randomNum = random(100)+1;
_root["picture"+randomNum]._alpha = 100;
}
What this does is when you click the button, a variable called randomNum is given a random between 1 and 100. It then uses the random to call the movieclip with the same instance name.
So if the random number was 30 , then the movieclip called picture30 will then be visible. Also , since its random, it will always be different everytime.
In 100 clicks Random can of course, make the same object appears several times - overlapping, nothing happens. Can it be avoided??
Can i make it in a way that one can not repeat. Ex: If randomly happens that object 45 is chosed after first click. Can i make that the 2nd click can not randomly choose object 45?
Ok, I forgot to take that problem into consideration but heres the solution. Change the code in your buttons to:
code:
on (release) {
onEnterFrame = function () {
randomNum = random(10)+1;
if (_root["picture"+randomNum]._alpha != 100) {
_root["picture"+randomNum]._alpha = 100;
delete (this.onEnterFrame);
}
};
}
What this does is randomizes a number and then checks if that corresponding movieclip is already visible , if not it'll choose another number until it finds the right movieclip that is currently invisible
Also , just a bit of warning that it might slow down a bit near the end. Not slow down your application but take longer to display the movieclip. Since it has to find the next avaiblable movieclip through random numbers , it'll take a bit longer when there are only 10 movieclips left.
There might be a better way to accomplish this method, but this works
Mandrade, my code originally did what you wanted, I just forgot to put in one line.
Anyways, as far as remembering the numbers...
Code:
on (release) {
randomNum = random(100)+1;
while (_root["picture"+randomNum]._alpha == 100) {
randomNum = int(random(100)+1);
}
_root["picture"+randomNum]._alpha = 100;
}
Hope that works!
Edit: Sorry Osteel, I didn't see your post. It looks like we took different approaches anyways. I haven't tested this out, but I feel like it would be more efficient than an onEnterFrame event.