View Full Version : Help with loops
SimoNomiS
01-23-2005, 08:14 AM
I am currently trying to make a movie clip shrink in width to about 10 pixels and when that happens turn visible to false and then turn another bar in the same location grow to the size that the other one was. Can anyone please help me with this... so far i have this but for some reason the second bar does not wait for the other one to finish before it expands. Please help it will be greatly apreciated. here is my code... (i know its bad)
var newsup:Boolean;
var aboutup:Number;
aboutup = 0;
newsup = true;
setProperty(about_mc, _visible, false);
about_btn.onRelease = function() {
aboutup = 0;
if (newsup=true) {
aboutup = 0;
news_mc.onEnterFrame = function() {
if (news_mc._width>9) {
news_mc._width = Number(news_mc._width)-10;
}
if (news_mc._width<=10) {
setProperty(news_mc, _visible, false);
newsup = false;
setProperty(about_mc, _visible, true);
aboutup = 1;
}
};
}
if (aboutup=1) {
about_mc.onEnterFrame = function() {
if (about_mc._width<496) {
about_mc._width = Number(about_mc._width)+10;
}
};
}
};
//This is my first post ever!!!
about_mc._visible = false;
about_btn.onPress = function() {
news_mc.onEnterFrame = function() {
news_mc._width -= 10;
if (news_mc._width < 9) delete this.onEnterFrame;
if (news_mc._width <= 10) {
news_mc._visible = false;
about_mc._visible = true;
about_mc.onEnterFrame = function() {
about_mc._width += 10;
if(about_mc._width > 496) delete this.onEnterFrame;
}
}
}
}//end of onPress function
If you want to use your own code, you can also do it like this:
(I removed the last if sentence and moved the about_mc.onEnterFrame function a couple of lines up! :)
var newsup:Boolean;
var aboutup:Number;
aboutup = 0;
newsup = true;
setProperty(about_mc, _visible, false);
about_btn.onRelease = function() {
aboutup = 0;
if (newsup=true) {
aboutup = 0;
news_mc.onEnterFrame = function() {
if (news_mc._width>9) {
news_mc._width = Number(news_mc._width)-10;
}
if (news_mc._width<=10) {
setProperty(news_mc, _visible, false);
newsup = false;
setProperty(about_mc, _visible, true);
aboutup = 1;
about_mc.onEnterFrame = function() {
if (about_mc._width<496) {
about_mc._width = Number(about_mc._width)+10;
}
}
}
}
}
}
//Have a nice day!
//Finn-Olav from Norway
SimoNomiS
01-23-2005, 05:11 PM
well thank you very much it works perfectly.
I have to change a couple of little things so that it does not continue expanding if you keep clicking on the button. i should just be able to move the command down in the action script. again thank you very much im glad that your first post helped out so much.
SimoNomiS
01-23-2005, 05:20 PM
i tired your code out and it works great but i can't get it to stop doing it once it gets to the desired size. it will stop moving on its own but if you keep clicking the about_btn it will grow by 10 no matter what size it is.
please help me again if you have time. thanks
//just throw in some return statements
about_mc._visible = false;
about_btn.onPress = function() {
news_mc.onEnterFrame = function() {
if (news_mc._width < 9) {
delete this.onEnterFrame;
return;
}
news_mc._width -= 10;
if (news_mc._width <= 10) {
news_mc._visible = false;
about_mc._visible = true;
about_mc.onEnterFrame = function() {
if(about_mc._width > 496) {
delete this.onEnterFrame;
return;
}
about_mc._width += 10;
}
}
}
}//end of onPress function
How do I get my code formatted as Actionscript? With color syntax. Seams to me that it happened automatically on my previous post :confused:
SimoNomiS
01-23-2005, 06:00 PM
i think that a moderator did it for you.
you have to put the code tag around it... should be
ok well i cant type it out so ill do it with zero's but replace them with o's
text here
I tried (take a look above), but I didnt get the color syntax
SimoNomiS
01-23-2005, 06:07 PM
i only know how to do that. the moderator put the color on there for us i think when he put our scripts in actionscript. angain thanks alot for your help.
edit... put in the tag spelled like this [ a s ] text here [ / a s ]
p.s. man you are so helpfull i wish i could give you some positive forum feedback or something cuase you helped me out a hell of a lot. thanks again and again.
SimoNomiS
01-23-2005, 06:33 PM
ok one last bit..
i have 5 different buttons that each need to shirnk the window up and then grow there own. the site also starts with a news window up. is there anyway to put all the action script into just one function that can be called on be each button. i think i know the basic things about it but it keeps giving me script errors. so just make all that into a function with 2 variables. to shirnk and to grow? please help again.
also if you want to check out what you have been helping me with its on this site....
www.satorifire.com
mcWichButton1Shows._visible = true;
mcWichButton2Shows._visible = false;
mcWichButton3Shows._visible = false;
mcWichButton4Shows._visible = false;
mcWichButton5Shows._visible = false;
theMcThatIsOpen = mcWichButton1Shows;
var inProgress = false;
mc_button1.onPress = function() {
if(!inProgress) {
doAllTheStuff(theMcThatIsOpen, mcWichButton1Shows);
theMcThatIsOpen = mcWichButton1Shows;
}
}
mc_button2.onPress = function() {
if(!inProgress) {
doAllTheStuff(theMcThatIsOpen, mcWichButton2Shows);
theMcThatIsOpen = mcWichButton2Shows;
}
}
mc_button3.onPress = function() {
if(!inProgress) {
doAllTheStuff(theMcThatIsOpen, mcWichButton3Shows);
theMcThatIsOpen = mcWichButton3Shows;
}
}
mc_button4.onPress = function() {
if(!inProgress) {
doAllTheStuff(theMcThatIsOpen, mcWichButton4Shows);
theMcThatIsOpen = mcWichButton4Shows;
}
}
mc_button5.onPress = function() {
if(!inProgress) {
doAllTheStuff(theMcThatIsOpen, mcWichButton5Shows);
theMcThatIsOpen = mcWichButton5Shows;
}
}
function doAllTheStuff(shrinkThis:MovieClip, expandThis:MovieClip) {
inProgress = true;
shrinkThis.onEnterFrame = function() {
if (shrinkThis._width < 9) {
delete this.onEnterFrame;
return;
}
shrinkThis._width -= 10;
if (shrinkThis._width <= 10) {
shrinkThis._visible = false;
expandThis._visible = true;
expandThis.onEnterFrame = function() {
if(expandThis._width > 496) {
delete this.onEnterFrame;
inProgress = false;
return;
}
expandThis._width += 10;
}
}
}
}//end of onPress function
SimoNomiS
01-23-2005, 07:54 PM
wow you are my new best friend... ill test it out and let you know how it works.
But you have the framework, so I hope you figure it out yourself.
I have to go.
SimoNomiS
01-23-2005, 08:18 PM
everything works great except if say newswindow1 is up and you click the button to load newswindow1 it will shrink then load again. is there anyway to disable the function if it is already up?
The only thing different is theese lines:
if((!inProgress) || (theMcThatIsOpen != mcWichButton1Shows)) {
if((!inProgress) || (theMcThatIsOpen != mcWichButton2Shows)) {
...
if((!inProgress) || (theMcThatIsOpen != mcWichButton5Shows)) {
What I do is to check if theMcThatIsOpen == mcWichButton5Shows. If it is then we do not run the doAllTheStuff function, because what we want to se on the screen is already there....right...!!!
Your biggest mistake in your own code was that you didnt delete your onEnterFrames. The onEnterFrame takes up a lot of cpu. So try to focus on that next time you develop something with interactive motion
Good work thow, you almost had it :)
mcWichButton1Shows._visible = true;
mcWichButton2Shows._visible = false;
mcWichButton3Shows._visible = false;
mcWichButton4Shows._visible = false;
mcWichButton5Shows._visible = false;
theMcThatIsOpen = mcWichButton1Shows;
var inProgress = false;
mc_button1.onPress = function() {
if((!inProgress) || (theMcThatIsOpen != mcWichButton1Shows)) {
doAllTheStuff(theMcThatIsOpen, mcWichButton1Shows);
theMcThatIsOpen = mcWichButton1Shows;
}
}
mc_button2.onPress = function() {
if((!inProgress) || (theMcThatIsOpen != mcWichButton2Shows)) {
doAllTheStuff(theMcThatIsOpen, mcWichButton2Shows);
theMcThatIsOpen = mcWichButton2Shows;
}
}
mc_button3.onPress = function() {
if((!inProgress) || (theMcThatIsOpen != mcWichButton3Shows)) {
doAllTheStuff(theMcThatIsOpen, mcWichButton3Shows);
theMcThatIsOpen = mcWichButton3Shows;
}
}
mc_button4.onPress = function() {
if((!inProgress) || (theMcThatIsOpen != mcWichButton4Shows)) {
doAllTheStuff(theMcThatIsOpen, mcWichButton4Shows);
theMcThatIsOpen = mcWichButton4Shows;
}
}
mc_button5.onPress = function() {
if((!inProgress) || (theMcThatIsOpen != mcWichButton5Shows)) {
doAllTheStuff(theMcThatIsOpen, mcWichButton5Shows);
theMcThatIsOpen = mcWichButton5Shows;
}
}
function doAllTheStuff(shrinkThis:MovieClip, expandThis:MovieClip) {
inProgress = true;
shrinkThis.onEnterFrame = function() {
if (shrinkThis._width < 9) {
delete this.onEnterFrame;
return;
}
shrinkThis._width -= 10;
if (shrinkThis._width <= 10) {
shrinkThis._visible = false;
expandThis._visible = true;
expandThis.onEnterFrame = function() {
if(expandThis._width > 496) {
delete this.onEnterFrame;
inProgress = false;
return;
}
expandThis._width += 10;
}
}
}
}//end of onPress function
Cool stuff Finn!
Maybe you couldnt shorten your script a little with a for loop like this:
theMcThatIsOpen = mcWichButton1Shows;
var inProgress = false;
for (var i = 1; i < 5; i++) {
//give it an iincrement for the onPress function
this["mc_button" + i].incr = i;
this["mc_button" + i].onPress = function () {
if ((!inProgress) || (theMcThatIsOpen != this._parent["mcWichButton" + this.i + "Shows"])) {
doAllTheStuff (this._parent["mcWichButton" + this.i + "Shows"]);
theMcThatIsOpen = this._parent["mcWichButton" + this.i + "Shows"];
}
};
this["mcWichButton" + i + "Shows"]._visible = false;
this.mcWichButton1Shows._visible = true;
}
function doAllTheStuff (expandThis:MovieClip) {
inProgress = true;
theMcThatIsOpen.onEnterFrame = function () {
if (theMcThatIsOpen._width < 9) {
theMcThatIsOpen.onEnterFrame = null;
return;
}
theMcThatIsOpen._width -= 10;
if (theMcThatIsOpen._width <= 10) {
theMcThatIsOpen._visible = false;
expandThis._visible = true;
expandThis.onEnterFrame = function () {
if (expandThis._width > 496) {
expandThis.onEnterFrame = null;
inProgress = false;
return;
}
expandThis._width += 10;
};
}
};
}
Not that it matters too much. Also I took out the first parameter of the function....Its always going to be that one that gets faded out :-)
I would probably have taken a slightly different approach in that I would have assigned to lastOpened variable to the button, thus I could assign or check using this._name.
As I said just shortens the code, and helps keep an eye on getting things done.
Good stuff!
Taff
SimoNomiS
01-24-2005, 05:59 PM
Thanks alot everybody...
taff your code looks very confusing so i dont know what to say but thanks for taking time to try and help me. Also... my buttons do not have the same names that he has... they have unike names ie. about_btn do i dont think the counting button thing would work. If it would really make the thing more reliable i could change all my movie clips and buttons to be numbers. anyway i will try out the new code when i get home but still for some reason there is a problem with stability that it doesn't work after a while. I can't tell if its certin buttons or what but after a while useally about three to four clicks one of the windows stays up casuing it to not work at all. check it out on www.satorifire.com to see what i mean.
SimoNomiS
01-25-2005, 04:07 AM
the code you gave me does not work for stoping the function if it is already open. I am going to post the exact code that i am useing because i changed the names of everything. Maybe i made a typo that you guys could catch or something. I am going to try renameing everything to what you names are and not change the code and see if it works.
Thanks for you help everyone and nice site taff (i checked it out) Finn i am very thankfull for all this code you have let me use.
My EXACT code...
stop ();
news_mc._visible = true;
about_mc._visible = false;
pictures_mc._visible = false;
custom_mc._visible = false;
contact_mc._visible = false;
shopping_mc._visible = false;
openmc = news_mc;
var inProgress = false;
news_btn.onPress = function () {
if (!inProgress) {
shrinkgrow (openmc, news_mc);
openmc = news_mc;
}
};
about_btn.onPress = function () {
if ((!inProgress) || (openmc != about_mc)) {
shrinkgrow (openmc, about_mc);
openmc = about_mc;
}
};
pictures_btn.onPress = function () {
if ((!inProgress) || (openmc != pictures_mc)) {
shrinkgrow (openmc, pictures_mc);
openmc = pictures_mc;
}
};
custom_btn.onPress = function () {
if ((!inProgress) || (openmc != custom_mc)) {
shrinkgrow (openmc, custom_mc);
openmc = custom_mc;
}
};
contact_btn.onPress = function () {
if ((!inProgress) || (openmc != contact_mc)) {
shrinkgrow (openmc, contact_mc);
openmc = contact_mc;
}
};
shopping_btn.onPress = function () {
if ((!inProgress) || (openmc != shopping_mc)) {
shrinkgrow (openmc, shopping_mc);
openmc = shopping_mc;
}
};
function shrinkgrow (shrinkThis:MovieClip, expandThis:MovieClip) {
inProgress = true;
shrinkThis.onEnterFrame = function () {
if (shrinkThis._width < 9) {
delete this.onEnterFrame;
return;
}
shrinkThis._width -= 10;
if (shrinkThis._width <= 10) {
shrinkThis._visible = false;
expandThis._visible = true;
expandThis.onEnterFrame = function () {
if (expandThis._width > 496) {
delete this.onEnterFrame;
inProgress = false;
return;
}
expandThis._width += 10;
};
}
};
}
SimoNomiS
01-25-2005, 06:18 PM
ok so i put in your code and changed it so all my buttons and movies were named acording to your script and still there are the same problems.
1. It will change mc's even if the one it is changing to is already up.
2. On the third menu change it messes up and leaves the clip up there for some reason.
please help me.
I totally agree with you. Of course, your modifications to the code does the same thing but more effective.
SimoNomiS
01-31-2005, 06:12 AM
very nice, very nice. now there is only one problem remaining.
I know how to stop this program but not sure how to code it.
i tryed your fla and the problem is there to.
the problem is when one mc is expanding and you click on another button.
when you click on the other button it sees that in progress is true so does nothing visible. But in the background it changes the mcthatisopen variable to the new button clicked. this means that when it is done expanding and you click on another one it trys to shrink the previosly clicked movie clip. But beacuse this one is not up it looks like nothing is happening.
im not quite sure how to fix this except maybe throw in some code that would shrink all open mc's not just the one that is open. then no matter what it would work... think you could help me out with that? thanks alot
EDIT....
ok so i was checking your code closer. on your fla the buttons 3, 4, 5 all have 1 line of code that 1 and 2 dont have.
the line of code is here...
notice that there is an extra line after the if statement that changes a variable...
is this suposed to be there and should the others have it?
mc_button2.onPress = function () {
if ((!inProgress) && (theMcThatIsOpen != mcWichButton2Shows)) {
doAllTheStuff (theMcThatIsOpen, mcWichButton2Shows);
theMcThatIsOpen = mcWichButton2Shows;
}
};
mc_button3.onPress = function () {
if ((!inProgress) && (theMcThatIsOpen != mcWichButton3Shows)) {
doAllTheStuff (theMcThatIsOpen, mcWichButton3Shows);
theMcThatIsOpen = mcWichButton3Shows;
}
theMcThatIsOpen = mcWichButton3Shows;
};
EDIT....
ok one more thing... mine does not work right. I am using your code exactly, with an added button #6. anyways for some reason that i can not figure out it stops on the third time. i tried posting my fla file but i think it is to big to fit on this site. If you could please pm me i could email it to you.
EDIT....
I was thinking of ways to make the code shorter and maybe that would make it work better... i came up with this...
Everybutton has the code that says to set the button that just opened to the one that is open in variables.
We could stick that line of code in the function so that it would only be one line of code instead of the 6 lines.
put it pretty much anywhere in the function would work. just put in this code...
theMcThatIsOpen = expandThis;
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.