Basic fade in fade out with buttons not working
Ive have a look and couldnt find anything that helped me. Im trying to build a website, however i havent used flash since as2 and all im trying to do is simply make no images appear on screen, then when one button is clicked it fades in, then when another, the original fades out and the other fade in.
So far when i click the buttons they fade in fine, but then clicking the other button nothing happens
, im not sure what i am doing wrong....
I have two buttons Film_btn and Sport_btn and i want them to fade in MainFilm_mc and SportMain_mc
Any help would be great, its driving me nuts!
always remeber ( especially on ETER_FRAME events) to remove event listeners when they are no longer needed.
you run the risk, in this case, of continuing to loop subtracting alpha values. zero is zero. once it is hit, stop it, otherwise you have to add back all those negative increments just to get back to zero!
look at this modified code, try it out, see what is happening,and then you can play with it and adjust it according to your needs.
i hope that can help[
Hi! Thanks for this, it worked perfectly! I've added a third button and it now works, meaning i can switch between all 3, however it doesnt actually fade in any more on the first click:
IE - when i load up the page, just the two buttons are there FILM and SPORT, when i click FILM the mc appears, but only at 0.1, i have to click it 10 times to get it to full opacity. When i click sport when its at full opacity, the sport_mc fades in completely, but the film_mc goes back to 0.1.
If i click sport_btn when film_mc is at 0.1, the sport_mc only goes to 0.1 aswell.
For now i have changed the + and - = to 1, so that it just appears, but im not sure how to automatically tell the code to repeat its self until the opacity gets to 1 in 0.1 increments.
I hope this post makes sense!
sorry, i am not really following at this point.
the code worked fine and then you added a 3rd button. now, you need to rework, and take into account all the possibilities. i am not sure now what you are trying to accomplish.
i used ( only because you used) an ENTER_FRAME Event to control the animations. that means that the funtion will keep firing every frame until told to stop by code or a condition. that is key to understanding these kinds of animations.
you might be better off exploring, and using, a tweening engine such as greensock's TweenLite.
then you can easily say : on button click A, tween a alpha to 1, b alpha to 0 and c alpha to 0.
on buton click B: tween a alpha to 0, b alpha to 1, c alpha to 0
on button click C, tween a alpha to 0, b alpha to 0 and c alpha to 1
( if that is your goal)
I mean i have the 3rd button working fine so that when i click button 1 what ever is on screen (either 2 or 3) disappears, when i click 2 whatever is on screen (either 1 or 3) disappears and so on for the final button SEE BELOW FOR CODE.
My problem is now that (with the current code) it takes two click on the button for the transition to fadein and the other out. I mean with one click the current image has gone from 100% to 50% transparent and the incoming image has gone from 0% to 50% transparent. I know how to make it full come in on one click, but i need a code for it to say keep repeating itself so that the image goes from 0% opacity to 100% opacity (or vice versa) automatically on one click.
QUOTE: "...My problem is .... it takes two click on the button for the transition to fadein and the other out. ....... i need a code for it to say keep repeating itself so that the image goes from 0% opacity to 100% opacity (or vice versa) automatically on one click...."
one problem is that now you need to check for multiple conditions (i.e. if a=0 AND b=1 AND c=1, then do X. ). you are currently checking for each condition sequentially, with the possibility of several cases being true , therefore executing code, with possible undesired results.
another problem is that you are using .9 and .1 as your conditional check. that was good while it was incrementing .1, and kept it at either a min of .1 or a max of .9 just as an illustration. you will need to adjust your conditional tests to 0 and 1( if that is waht you are expecting).
note: you will not see a transition with .5, as you are asking it to take 2 steps ( .5 each) to the final alpha. that is carried out only over 2 frame rate, which is faster than your eye can see. so one question is, why use ENTER_FRAME? why not just declare the Event click as a MOUSE_EVENT and save the processor from dealing with ENTER_FRAME? ( in other words, it is overkill).
once again, if you want animation flexibility and code simplicity, download and use greensock's TweenLite. the following code would make it do what i think you are trying to achieve. downlaod the swf to see it in action
Yes, that worked great, i thought i could do it the way i originally planned, but clearly not!