hi someone helped me out with this code and when i run it i get this error
1120: Access of undefined property circle_mc.
var blueTween:Tween = new Tween (circle_mc.blue_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
im completley new to actionscript and was wondering if someone could tell me what the error means?
Thanks
Code:
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
var yellowTween:Tween = new Tween (circle_mc.yellow_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
// this tweens the yellow_mc inside of circle_mc.
yellowTween.addEventListener(TweenEvent.MOTION_FINISH, startBlue);
// this listens for the yellowTween to finish its event and when its done it triggers startBlue function.
function startBlue(event:TweenEvent):void
{
var blueTween:Tween = new Tween (circle_mc.blue_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
// in this function it starts the blue_mc to tween.
blueTween.addEventListener(TweenEvent.MOTION_FINISH, startRed);
//also, it listens for the blueTween to finish its motion tween. now, i had to put this inside of this function rather than outside because i declared variable ofblueTween insie of this startBlue function. so in ordor to recognize the blueTween, it has to be within the same location.
}
function startRed(event:TweenEvent):void
{
var redTween:Tween = new Tween (circle_mc.red_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true);
// so after blue is finished, it triggered red Tween and this is the red function.
}
Well here is what I would probably do. Tweens are weird in that they are in fact reusable, but I have not found a way to create them without passing the initial parameters, which in turn stars the tween. So basically what I normally end up doing with them is creating them and then immediately stopping them, or create them with a starting and ending value that is the same (I do this when I will be customizing the values later). So if I understand you correctly, you want that sequence of tween to loop. I did not actually test this, but you can give it a try and see how it works for you:
var yellowTween:Tween = new Tween (circle_mc.yellow_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
yellowTween.stop();
yellowTween.addEventListener(TweenEvent.MOTION_FIN ISH, startBlue);
var blueTween:Tween = new Tween (circle_mc.blue_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
blueTween.stop();
blueTween.addEventListener(TweenEvent.MOTION_FINIS H, startRed);
var redTween:Tween = new Tween (circle_mc.red_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true);
redTween.stop()
blueTween.addEventListener(TweenEvent.MOTION_FINIS H, startYellow);
yellowTween.start();
function startBlue(event:TweenEvent):void
{
blueTween.start();
}
function startRed(event:TweenEvent):void
{
redTween.start()
}
function startYellow(event:TweenEvent):void
{
yellowTween.start();
}
by doing it this way you are reusing the tween objects and only assigning the event listeners once instead of recreating them and assigning them each time the TweenEvent.MOTION_FINISH is triggered. Since each TweenEvent.MOTION_FINISH triggers the next tween to start, you basically just set the loop up and let it run.
var yellowTween:Tween = new Tween (circle_mc.yellow_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
yellowTween.stop();
yellowTween.addEventListener(TweenEvent.MOTION_FIN ISH, startBlue);
var blueTween:Tween = new Tween (circle_mc.blue_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true );
blueTween.stop();
blueTween.addEventListener(TweenEvent.MOTION_FINIS H, startRed);
var redTween:Tween = new Tween (circle_mc.red_mc, "alpha", None.easeInOut, 1 , 0 , 1 , true);
redTween.stop()
redTween.addEventListener(TweenEvent.MOTION_FINISH , startYellow);
yellowTween.start();
function startBlue(event:TweenEvent):void
{
blueTween.start();
}
function startRed(event:TweenEvent):void
{
redTween.start()
}
function startYellow(event:TweenEvent):void
{
yellowTween.start();
}
the first time it goes it loops over each other giving a sorta cross fade effect the second time is different
id like each to fade in straight after each other, and how do i slow them down?
my fla is attached if it helps to use my example
and the swf to view it
So the second set of rotations is what you want correct? You slow them down by making the tween take longer which is the number value before the last parameter true.
Again this has to do with the tweens starting. Since your circles are on top of each other, the first time through you see the colors mixing, but after the first pass, they are all hidden. Add the following:
function startBlue(event:TweenEvent):void
{
blueTween.start();
}
function startRed(event:TweenEvent):void
{
redTween.start()
}
function startYellow(event:TweenEvent):void
{
yellowTween.start();
}
function fadeOut(event:TweenEvent) {
event.target.removeEventListener(TweenEvent.MOTION _FINISH, fadeOut);
event.target.addEventListener(TweenEvent.MOTION_FI NISH, startNext);
event.target.begin = 1;
event.target.finish = 0;
event.target.start();
}
function startNext(event:TweenEvent) {
event.target.removeEventListener(TweenEvent.MOTION _FINISH, startNext);
event.target.obj.nextTween.addEventListener(TweenE vent.MOTION_FINISH, fadeOut);
event.target.obj.nextTween.begin = 0;
event.target.obj.nextTween.finish = 1;
event.target.obj.nextTween.start();
}
a bit simpler than writing start and end function for each tween.
Will start with the commented code:
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
/*
Create tween objects and immediately stop them so that they can be re-used.
*/
var yellowTween:Tween = new Tween (circle_mc.yellow_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true );
yellowTween.stop();
var blueTween:Tween = new Tween (circle_mc.blue_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true );
blueTween.stop();
var redTween:Tween = new Tween (circle_mc.red_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true);
redTween.stop();
/*Add an event listener to the first tween to trigger the fade in the opposite
direction. Subsequent listeners will be assigned and removed in the event
handler functions.
*/
yellowTween.addEventListener(TweenEvent.MOTION_FIN ISH, fadeOut);
/*
Since movie clips allow for the creation of dynamic properties (aka variables), simply create a
reference to the next tween that should be triggered directly on the clip. With
this system you could easily add additional clips by creating a new tween and adding
another reference on the new clip to be tweened.
*/
circle_mc.yellow_mc.nextTween = blueTween;
circle_mc.blue_mc.nextTween = redTween;
circle_mc.red_mc.nextTween = yellowTween;
/*
Start the first tween to kick off the sequence. This should be the tween that you
added the event listener to in the previous code.
*/
yellowTween.start();
/*
Create a generic handler for the end of the fade in event. Since the TweenEvent object
holds a reference to the tween that caused the even, we can reference that tween via
the event.target property.
*/
function fadeOut(event:TweenEvent) {
/*remove the event listener that triggers this function from the tween since we have
gotten past the point of needed it and we don't want it to complete with the next part
of the sequence.
*/
event.target.removeEventListener(TweenEvent.MOTION _FINISH, fadeOut);
/*Add a new event listener that will trigger the next part of the sequence*/
event.target.addEventListener(TweenEvent.MOTION_FI NISH, startNext);
/*Set the begin and finish properties of the tween object to the opposites
of those we used to create the fade in effect. I had originally tried to do
this with the built in yoyo function, but it produced unexpected results.
*/
event.target.begin = 1;
event.target.finish = 0;
/*Restart the tween with the new properties, when this tween is finished,
it will trigger the new event handler we assigned in this function and
continue the sequence.
*/
event.target.start();
}
/*Now that the tween has faded in and out, start the next tween. Again since TweenEvent
holds a reference to the tween that triggered the event, we can reference that tween.
Additionally, since the tween object holds a reference to the clip being tweened,
we can reference the properties of that clip. In this case we are interested in the
nextTween property we assigned in the previous code as this is what we will use
to start the next tween.
*/
function startNext(event:TweenEvent) {
/*Removed the event listener that triggered this function.*/
event.target.removeEventListener(TweenEvent.MOTION _FINISH, startNext);
/*
event.target is the tween that triggered the function. obj is the property on
the tween object that holds a reference to the clip being tweened. hence, we can
reference the next tween to be triggered by accessing the nextTween property we created.
*/
/*
add a listener to trigger the fade out function completing the logical loop.
*/
event.target.obj.nextTween.addEventListener(TweenE vent.MOTION_FINISH, fadeOut);
/*Reset the values of the tween so that the effect is to fade in.*/
event.target.obj.nextTween.begin = 0;
event.target.obj.nextTween.finish = 1;
/*start the tween and the cycle repeat itself.*/
event.target.obj.nextTween.start();
}
Was able to simplify this even further. It will depend a bit on the order of the clips in the FLA, but this is even more flexible. Take a look at what I did in the fla with text_mc
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
var text1Tween:Tween = new Tween (text_mc.text_1, "alpha", None.easeInOut, 0 , 1 , 2 , true );
text1Tween.stop();
text1Tween.addEventListener(TweenEvent.MOTION_FINI SH,fadeOutText);
if (text_mc.numChildren > 1) {
for (var c:int = text_mc.numChildren-1; c>=0; c--) {
var clip:Object = text_mc.getChildAt(c);
clip.alpha = 0;
if (c > 0){
clip.nextClip = text_mc.getChildAt(c-1);
}else{
clip.nextClip = text_mc.getChildAt(text_mc.numChildren-1);
}
}
}
text1Tween.start();
Will also work for your other clips. As long as they are all going to use the same timings, then this should be fine:
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
var yellowTween:Tween = new Tween (pics_mc.yellow_mc, "alpha", None.easeInOut, 0 , 1 , 2 , true );
yellowTween.stop();
yellowTween.addEventListener(TweenEvent.MOTION_FIN ISH,fadeOut);
i dotn get some of the code, could you explain it to me please?
also with the text movie clips i with the backgrounds (the big squares) i didnt want the squares to fade in, just to change colour then the text fades ontop of it
thankyou so much for your help though, youve been so helpful so far
Thanks!