• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

Need help with flash 8 actionsript using the tween class

Ok, just to be clear - I'm a complete neophyte with programming in general and actionscript specifically.

I have a simple graphic on my stage that I want to have fade in or out with actionscript.  I want to place actionscript in the timeline to control when I want this item to fade in  and when I want it to fade out.   Beyond that I'm clueless as to how to make that happen.

I found the script I've pasted below, which seems to do what I'm looking for - but it is controlled by a mouse rollover - not a specific timeline occurrence.

I'm hoping someone could help me to change this script (and tell me how to use it on the timeline) so that I can have my graphic fade in and out when I need it.

Thanks a million, in advance, for any and all help with this.

Here is the script I found:
//first import the class libraries
import mx.transitions.Tween;
import mx.transitions.easing.Regular;

//now initialize the tween object
myButton.alphaTween= new Tween(myButton, "_alpha", Regular.easeOut, 50, 50, .3, true);

function onRollOutHandler(){

function onRollOverHandler(){

myButton.onRollOver = onRollOverHandler;
myButton.onRollOut = onRollOutHandler;

  • 4
  • 4
1 Solution
Being a beginner, why not let flash do the hard part for you?  You can create a new movie clip, add that graphic to it, extend the timeline a ways by adding a new keyframe, change the alpha setting on the graphic to where you want it, and tell flash to tween it for you.  Then instead of placing the graphic in your main timeline, place the movie clip in the main timeline (and give it a name) and you can reference it by doing something like MovieClipName.gotoAndPlay(1);  This way if you later decided to add more to the tween or add more effects to the graphic, you just edit the movieclip rather than having to edit your main timeline.
marglarAuthor Commented:
I think I understand what you are saying...

So, I create a movie clip with my graphic in it and extend it out, lets say 20 fames.
Then I could put a keyframe at the beginning, middle and end.  
The beginning keyframe would have a 0% alpha, the middle 100% and the end 0% again.  ...giving me the fade in and back out I'm looking for.

I'm not sure I understand the bit about MovieClipName.gotoAndPlay(1);
Lets say I name my movieclip  box_mc   so would I simply put in the timeline (at the point I want it to start..)   box_mc.gotoAndPlay(1);    ?   Is it really that simple or am I missing something?    

Does my movieclip actually have to be on the timeline somewhere or can it just exist in the library?

this is great, thanks for the help!
It's really that simple.  Create the new movie clip and put the graphic on frame 1.  Then go to frame 10 and add a keyframe.  Click on the image in frame 10 and change the alpha to 0%.  Add Stop(); to the actionscript in frame 10.  Now create another keyframe in frame 11.  The image will still be there, and it's alpha should still be 0%.  Add the actionscript Play(); to that frame.  Add a keyframe at 20, change the alpha on the image to 100% and add the actionscript Stop(); to that frame.   Then go to frame 10 and tell it do a motion tween.  Do the same thing on frame 20.  You're all set.     Now you can add that movie clip to your main timeline and name it "box_mc" as you said.    Now you can fade out by doing box_mc.gotoAndPlay(1); (which will make it play from frame 1 to 10)  and you can fade in by doing box_mc.gotoAndPlay(11); (which will make it play from frame 11 to 20).  

This is just an example, feel free to reverse the fade in/fade out by making frame 1 and 20 0% alpha and frames 10 and 11 100% alpha.  Flash is a very simple to use application once you learn your way around the interface.  Good luck, and if you have any more questions just ask!

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

marglarAuthor Commented:
Sorry, a bit more clarification...

In my movieclip example, I'd use a motion tween to do the fade, of course.

The bit I'm confused on is this:

So, I have a movie playing in the main timeline.  I want this graphic to fade in and out on top of that playing movie to obscure parts of it and then reveal them again.  (I'm fading in and out the transition between images, my graphic is the same color as the background so it appears that the images are fading in and out).

Are you saying that I can have my above described movieclip simply called from the timeline to play over the top of the rest of the playing main timeline?   Could you show me a simple example of that?
marglarAuthor Commented:
...hehehe sorry, we wrote our responses at the same time.

I'm confused about adding the movieclip to the main timeline.   How do I do that so that it doesn't show up until I want it to?

When I think of adding something to the timeline I think of dragging it to the stage in a particular frame...
I think I originally told you backwards of what you wanted.  So to clarify what you want, here are the keyframes you'd need in that movie clip and what should go in them:

Frame1 - graphic/symbol with 0% alpha. Actionscript:  Stop();
Frame2 - graphic/symbol with 0% alpha. Actionscript:  Play();
Frame10 - graphic/symbol with 100% alpha.  Actionscript:  Stop();
Frame11 = graphic/symbol with 100% alpha.  Actionscript:  Play();
Frame20 = graphic/symbol with 0% alpha.  Actionscript:  Stop();

THEN - to make it work from your main timeline (if you named the movie clip "box_mc"):
To fade IN - box_mc.gotoAndPlay(2);
to fade OUT - box_mc.gotoAndPlay(11);

Of course you can add more or take out some frames if you want to make it transition slower or faster too.
marglarAuthor Commented:
That did it Swindle!  

Thanks a million!  It works like a champ!  This not only taught me some cool stuff about flash, but also will save me tons of work and time!

Thanks again!
No problem, I'm glad I was able to help!

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now