PDA

View Full Version : Actionscipt controlling alpha - help!!!


Kit Fox
05-17-2008, 10:12 AM
Hi All

Although I am not new to Flash, my ActionScript is very minimal and I was hoping you can help me with this problem. I need to make a button that controls the behavior and alpha of a movie clip. The button must:

Make the movieclip fade to 0 alpha
Once at 0 Alpha, advance the timeline of the movieclip to another point
Once this advance is done, fade the movieclip back to 100 alpha

I have tried cobbling together bits of script I have picked up form forums, but this is beyond me. Help!!!

Thanks,

Kit Fox
:p

atomic
05-17-2008, 01:47 PM
Better to attach your go at it .fla, to this forum...

It needs to be zipped up to be able to attach it, and no larger than 500KBs once zipped up.

farvan
05-17-2008, 01:49 PM
put that into a movieclip.
name the movieclip what ever you want

onClipEvent(enterFrame) {
if( go == 1) {
//every frame the movieclip alpha goes down - 5
this._alpha -= 5
//if statement checks to see if alpha is less than zero, and if it is goto and play the target frame
if(this._alpha <0) {
_root.gotoAndPlay(frame)
}
}
}

Put this into a button
on(press) {
//tells the movieclip that go = 1 once go = 1 it triggers the alpha
tellTarget(_root.whatyounamedyourmovieclip) {
go = 1
}
}

Kit Fox
05-18-2008, 02:51 PM
Hi farvan & atomic

Thanks so much for your replies - I am nearly there!

atomic - good point. I now attach the .fla in zipped format. Do take a look if you are interested.

farvan - this is great. I have one problem and one query. The problem is that the code you kindly suggested will not make the movie return to 100 alpha after the gotoAndPlay code has been executed. I tried a few times to do this but to no avail.

My query is that can I assign the same script to various buttons on the main timeline to move the playhead in the movie to different point? Of course, I will change the "go ==" number.

:confused:

PS - you will also see I altered your script a little to stop the alpha from continually reducing below 0. I think. :eek:

farvan
05-19-2008, 04:44 PM
onClipEvent(load) {
alphacontrol = 5
go = 0
}

onClipEvent(enterFrame) {
if( go == 1) {
this._alpha -= alphacontrol
if(this._alpha <0) {
_root.gotoAndPlay(frame)
alphacontrol = -5


}
}
}
onClipEvent(enterFrame) {
if (this._alpha > 100) {
_alpha = 100
go = 0
alphacontrol = 5
}
}

put this into the movieclip and it should work.

Kit Fox
05-19-2008, 08:22 PM
Hi farvan

Thanks! This is totally cool. ;)

One last thing (please don't hit me) - How do I apply this script so that different buttons make the playhead move to different points on the movieclip's timeline?

I attach my latest version. You can see I tried to put different "if" statements in, but this does not seem to work. It works for the first button you click, but not for any subsequent ones after that.

:confused:

Really appreciate your help with this!

farvan
05-20-2008, 12:09 PM
The Attach should do it.
I have no idea why yours wasn't working, so instead I just made it point to the frame number instead of the frame label.

For some reason some of them wouldn't point to the correct frame, but if I pointed it towards the frame before it, it worked.

I also put each If into its own event.
Well that should do it.

Kit Fox
05-21-2008, 06:33 PM
Hi farvan

You're completely right - it seems to work fine when you put in frame numbers.

Thank you so much for all your help on this - I REALLY appreciate it!

If you go to www.adaz.co.uk in about two weeks you'll see the fruits of my labor.

Cheers,

Kit Fox.

farvan
05-22-2008, 03:34 AM
No problem.
glad to help.

farvan
05-22-2008, 01:15 PM
While looking at a filter pack...I realized what I made can do the same thing.
so in case you wanted to make a blur,glow,bevel out and back in.
just use the sample code.

if you replace blur1 in either x or y and change it to 0
you get a neat little effect.
it is in a loop right now.
after:

if(blur1 > 100) {
put your gotoAndStop(frame)

also turning down the quality of the blur makes a neat effect.