Hello everyone!
I see that your interested in seeing how to include AS 3.0 to your flash design. First, before we even begin with AS 3.0, let me start with talking about what AS 3.0 can do for your flash project. AS 3.0 can help your flash project to be more interactive then it already is. When you need somethign to happen when something is clicked or rolled-over or even rolled-off. Take user data and do "something" with it. Knowing that this is an art site, knowing some programming will help you in the long run.
I wanted to keep that as brief as possible so we can get to the fun part, CODING!!!!! YAY!!! :-P. Im going to go briefly over how to make a button using actionscript. Now you may be wondering (if you have used flash before) i can just use the button symbol. That would be best if you wanted to make a basic button, but if you wanted to add more animation like a seperate movie clip playing on roll over or even a roll-out option, you would need AS 3.0. Well open up a new flash file and make sure you use the ActionScript 3.0 file type.
GETTING TO ACTION PANEL:
So lets get started: if you havent ever used AS 3.0 before you prob dont even know how to input code. Well all you need to do is add a new layer in you main timeline, name it "actions", and on the first keyframe press f9 (MAC option + 9) and you actions panel should come up. Close out of that for know and lets design the button.
BUTTON CREATION:
Design a button in a "stand alone" state. This means when nothing is happening to it. What were going to create is a button that is slightly transparent ("alpha") and then "tweens" to 100% visible when rolled-Over and then tweens back to slightly transparent again when rolled-out all using AS 3.0. So take a few min. to create a button and put it on your stage in a layer called "Button."
CONVERT TO SYMBOL:
You now want to take what you created and convert it to a symbol. Right click your button and click "convert to smybol" now your first intention is going to be to convert to a button but your going to want to convert it to a movie clip. Name it Button and click OK. IMPORTANT STEP!!!!!! GIVE IT A INSTANCE NAME!! This will allow you to use it in AS 3.0. To do this single click your button(which is now a movie clip :-P) and in your property panel you should see an instance name input box. Type in there button_mc and press ENTER. You button can now be used in AS 3.0
SCRIPTING:
Its time to script! ok open up your actions panel (if you dont know how to do this refer to the beginning of this article) and you should see nothing there. copy and paste the following:
//imports everything you need
import fl.transitions.Tween;
import fl.transitions.easing.*;
//default value
button_mc.alpha = .7;
//Event Listeners
button_mc.addEventListener(MouseEvent.ROLL_OVER, buttonOver);
button_mc.addEventListener(MouseEvent.ROLL_OUT, buttonOut);
//functions
function buttonOver(e:MouseEvent):void
{
new Tween(button_mc,"alpha", Strong.easeOut, .7, 1, 24, false);
}
function buttonOut(e:MouseEvent):void
{
new Tween(button_mc,"alpha", Strong.easeOut, e.currentTarget.alpha, .7, 24, false);
}
Now you might be pulling you hair out looking at this but maybe not. If not no need to read on lol. But if you are this is the explaination of the code.
//imports everything you need
import fl.transitions.Tween;
import fl.transitions.easing.*;
simply this tells flash to import these functions. this allows you to ease things in and out and to tween your movie clips.
//default value
button_mc.alpha = .7;
We want your button to start automatically slightly transparent so when its open this code allows that to happen.
//Event Listeners
button_mc.addEventListener(MouseEvent.ROLL_OVER, buttonOver);
button_mc.addEventListener(MouseEvent.ROLL_OUT, buttonOut);
Event Listeners are important in AS 3.0. It basically does what its called.....listens for something. Basically the setup is this :
InstanceNameOfWhatYourEffecting.addEventListener(WhatKindOfEVENT.TheAction, FunctionName);
in the example above were saying listen for a MouseEvent that is Rolling over button_mc. if that happens execute function buttonOver.
//functions
function buttonOver(e:MouseEvent):void
{
new Tween(button_mc,"alpha", Strong.easeOut, .7, 1, 24, false);
}
function buttonOut(e:MouseEvent):void
{
new Tween(button_mc,"alpha", Strong.easeOut, e.currentTarget.alpha, .7, 24, false);
}
functions are the guts of the code. this says what to do when "something" happens. now lets break it up.
function buttonOver(e:MouseEvent):void
this is naming the function buttonOut. also it stores the MouseEvent into a variable e and void means that it returns no data (i.e numbers or strings). Anything you want the function to do goes between the { }.
new Tween(button_mc,"alpha", Strong.easeOut, .7, 1, 24, false);
this is the tween your button is doing. basically your makeing a new tween and this is the setup of it:
new Tween(WhatsBeingEffected."PropertyBeEffected",HowYouWantTweenToLook,StartValue, EndValue,TimeItTakesToTween,false = use keyframes for time true = use seconds for time);
the only other part needing explaining is the e.currentTarget.alpha. This says that the target making the function happen alpha is now the new start position. We do this because we dont want a "snap" effect. If we put 1 there then if the user rolled over before the tween was done, the alpha would jump to 100% alpha and tween back down. We dont want that so we take the curret alpha as the new start position so no jump happens.
And thats about it. test the movie. if your having any trouble at all please post a comment and ill try to help. This is a bit tough i know at first especially learning through reading but im here to answer any questions. :-)
Next Time we'll be discussing FlashVars (Pulling variables from HTML to use in actionscript ;-))
hope you enjoyed,
Eric Hoanshelt