Jump to content
Search Community

Simple mc animation

attentions test
Moderator Tag

Recommended Posts

Hi guys,

 

This is probably pretty simple to do, but im struggling big time.

I have this movieclip that loops on stage, when the movieclip is clicked a new one loads on top of it and the other one fades. When the second movieclip is finished playing it fades and the first one loads back up again looping.

 

Any help is very much appriciated, also i attached a ss possibly explaining it better.

Z27Ut.jpg

Link to comment
Share on other sites

Hi,

 

Hi, welcome to the forums.

 

I made a very basic example for you illustrating the interactions you described to the best of my understanding.

 

 

Attached is Flash CS4 AS3 document. please save it in a folder that contains the greensock com directory.

 

the code looks like this:

 

 

import com.greensock.*;
import com.greensock.easing.*;
import flash.events.MouseEvent;

//hide circle on load
TweenMax.to(circle_mc, 0, {autoAlpha:0});

rectangle_mc.buttonMode = true;
rectangle_mc.addEventListener(MouseEvent.CLICK, showCircle);



function showCircle(e:MouseEvent):void{
circle_mc.gotoAndPlay(1);
TweenMax.to(rectangle_mc, .5, {autoAlpha:0});
TweenMax.to(circle_mc, .5, {autoAlpha:1});
}

//this function is called from the last frame of the circle_mc's timeline animation
function showRectangle(){
rectangle_mc.gotoAndPlay(1);
TweenMax.to(rectangle_mc, .5, {autoAlpha:1});
TweenMax.to(circle_mc, .5, {autoAlpha:0});
}

click_fade_replace_CS4_AS3.zip

Link to comment
Share on other sites

Wow Carl this is fantastic, thanks so much! I've added another rectangle_mc/circle_mc which has the same function as the first one it would just play another videoclip.

 

Two more questions: 1. how do you either disable the ability to click on other mc if one is currently running / or simply just stop the one running and play the one clicked. The idea right now is when you click rectangle_mc it would run a short flv videoclip.

 

2. What is the best and easiest way to embed an flv/mp4 videoclip - it would go inside circle_mc, i guess i could do it via flvplayback, extend the timeline to a certain point and call this at the end MovieClip(this.parent).showRectangle();

 

Not sure this would be helpful to anyone but a rookie like me, but i added mouseover / mouseout on first button.

 

import com.greensock.*; import com.greensock.easing.*; import flash.events.MouseEvent; //hide circle on load TweenMax.to(circle_mc, 0, {autoAlpha:0}); TweenMax.to(circle_mc2, 0, {autoAlpha:0}); TweenMax.to(over, 0, {autoAlpha:0}); rectangle_mc.buttonMode = true; rectangle_mc.addEventListener(MouseEvent.CLICK, showCircle); rectangle_mc.addEventListener(MouseEvent.MOUSE_OVER, navOver); rectangle_mc.addEventListener(MouseEvent.MOUSE_OUT, navOut); rectangle_mc2.buttonMode = true; rectangle_mc2.addEventListener(MouseEvent.CLICK, showCircle2); function navOver(e:MouseEvent):void{ over.play(); trace("you rolled over me"); TweenMax.to(over, .5, {autoAlpha:1}); } function navOut(e:MouseEvent):void{ over.play(); trace("you rolled off me"); TweenMax.to(over, .5, {autoAlpha:0}); } function showCircle(e:MouseEvent):void{ circle_mc.gotoAndPlay(1); TweenMax.to(rectangle_mc, .5, {autoAlpha:0}); TweenMax.to(circle_mc, .5, {autoAlpha:1}); } //this function is called from the last frame of the circle_mc's timeline animation function showRectangle(){ rectangle_mc.gotoAndPlay(1); TweenMax.to(rectangle_mc, .5, {autoAlpha:1}); TweenMax.to(circle_mc, .5, {autoAlpha:0}); } function showCircle2(e:MouseEvent):void{ circle_mc2.gotoAndPlay(1); TweenMax.to(rectangle_mc2, .5, {autoAlpha:0}); TweenMax.to(circle_mc2, .5, {autoAlpha:1}); } //this function is called from the last frame of the circle_mc's timeline animation function showRectangle2(){ rectangle_mc2.gotoAndPlay(1); TweenMax.to(rectangle_mc2, .5, {autoAlpha:1}); TweenMax.to(circle_mc2, .5, {autoAlpha:0}); } 

Link to comment
Share on other sites

Hi,

 

Very glad that helped. Please realize that these forums are very active and we need to stay focused on offering support to issues that pertain directly to the GreenSock tools. We like to help folks as much as we can but have to be careful not to spend a lot of time on general Flash or actionscript issues.

 

That being said, I attached a file that should help you understand how to track which clip is currently playing and disable it when another clip is activated. In a nutshell there is a variable called active_mc that stores a reference to the recently clicked clip.

 

whenever you click on any clip (mc), actions run that stop the animation on the active_mc and then active_mc is updated to store the most recently clicked clip.

 

code:

 

var active_mc:MovieClip;

mc1.buttonMode = mc2.buttonMode = mc3.buttonMode = true;

mc1.addEventListener(MouseEvent.CLICK, playMe);
mc2.addEventListener(MouseEvent.CLICK, playMe);
mc3.addEventListener(MouseEvent.CLICK, playMe);

mc1.gotoAndStop(1);
mc2.gotoAndStop(1);
mc3.gotoAndStop(1);

function playMe(e:MouseEvent):void {
//before a clip is clicked, no mc is active.
//set active_mc = to the clicked mc on the first click
if (! active_mc) {
active_mc = e.target as MovieClip;
active_mc.gotoAndPlay(1);
}

//after the first item is clicked, this code will run on every click
else {
active_mc.gotoAndStop(1);
active_mc = e.target as MovieClip;
active_mc.gotoAndPlay(1);
}


}

 

file attached.

 

Hope that helps. Unfortunately, I'm not a huge fan of the FLVPlayback component and I haven't touched it in awhile so I really don't know what would be best for that aspect of your project.

 

enjoy the GreenSock tools. you are off to a great start.

 

-carl

switchActive_CS4_AS3.zip

Link to comment
Share on other sites

Thanks Carl, you are very helpful!

 

I tried combining your latest code with the first one above, but i'm having issues since i sort of have two buttons in the first one. So i tried making "circle_mc" as a button. But when another button is clicked "rectangle_mc2" the "circle_mc" just stops. How do you make "circle_mc" switch to "rectangle_mc" ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...