Jump to content
Search Community

Error in pause tween [SOLVED]

grollaz test
Moderator Tag

Recommended Posts

Hi, i have 1 tween (loghi1) for 1 mc on the root (marchi01) and 10 buttons on root of marchi01, for to start the tween i use this code in the root of the movie:

ON THE ROOT OF MOVIE:

function startmarchi() {
var loghi1:TweenMax = new TweenMax(marchi01, 30, {x:-1090, ease:Linear.easeNone, onComplete:riavvolgi1});
}

function riavvolgi1() {
marchi01.x=3286;
TweenMax.to(marchi01, 60, {x:-1090, ease:Linear.easeNone, loop:100});
}

startmarchi();

 

BUTTON ON THE ROOT OF "marchi01":

annarachele.addEventListener(MouseEvent.MOUSE_OVER, pausa);
function pausa(event:MouseEvent):void {
loghi1.pause();
}
annarachele.addEventListener(MouseEvent.MOUSE_OVER, riprendi);
function riprendi(event:MouseEvent):void {
loghi1.resume();
}
}

..but it not work, give to me an error, what i can do?

Tahnks.

Link to comment
Share on other sites

The problem is that you're using a local variable in your function which gets deleted as soon as the function finishes. So when you do this:

 

function startmarchi() {
  var loghi1:TweenMax = new TweenMax(marchi01, 30, {x:-1090, ease:Linear.easeNone, onComplete:riavvolgi1});
}

 

The loghi1 variable gets removed from memory immediately when startmarchi() finishes running. Then if you try referencing that variable outside that function, you'll get an error. That's just how Flash works - it has nothing to do with TweenMax.

 

The solution is to use a variable that's defined outside your function (not a local variable). Like:

 

var loghi1:TweenMax;
function startmarchi() {
  loghi1 = new TweenMax(marchi01, 30, {x:-1090, ease:Linear.easeNone, onComplete:riavvolgi1});
}

Link to comment
Share on other sites

The problem has to do with the way you set up your FLA and where you declared those variables. You're declaring them on the main timeline, but then you're trying to reference them inside of the loghi MovieClip.

 

I'd strongly discourage putting code inside nested MovieClip frames, but if you must, you could just reference the variables you created on the parent MovieClip timeline like:

 

import gs.*;
var loghi1:TweenMax = (this.parent as MovieClip).loghi1;
var loghi2:TweenMax = (this.parent as MovieClip).loghi2;

 

But again, this is kinda clunky.

Link to comment
Share on other sites

hello, I have now changed the code and everything is on a main timeline:

import gs.*;
import gs.easing.*;

var loghi1:TweenMax;
var loghi2:TweenMax;

function startmarchi() {
loghi1=new TweenMax(marchi01,30,{x:-1090,ease:Linear.easeNone,onComplete:riavvolgi1});
loghi2=new TweenMax(marchi02,60,{x:-1090,ease:Linear.easeNone,onComplete:riavvolgi2});
//TweenMax.to(marchi01, 30, {x:-1090, ease:Linear.easeNone, onComplete:riavvolgi1});
//TweenMax.to(marchi02, 60, {x:-1090, ease:Linear.easeNone, onComplete:riavvolgi2});
}
function riavvolgi1() {
marchi01.x=3286;
TweenMax.to(marchi01, 60, {x:-1090, ease:Linear.easeNone, loop:100});
}
function riavvolgi2() {
marchi02.x=3286;
TweenMax.to(marchi02, 60, {x:-1090, ease:Linear.easeNone, loop:100});
}
startmarchi();
//
marchi01.annarachele.buttonMode=true;
//
marchi01.annarachele.addEventListener(MouseEvent.MOUSE_OVER, pausa);
function pausa(event:MouseEvent):void {
loghi1.pause();
loghi2.pause();
}
marchi01.annarachele.addEventListener(MouseEvent.MOUSE_OVER, riprendi);
function riprendi(event:MouseEvent):void {
loghi1.resume();
loghi2.resume();
}
marchi01.annarachele.addEventListener(MouseEvent.CLICK, apri_annarachele);
function apri_annarachele(event:MouseEvent):void {
var url:URLRequest=new URLRequest("http://www.annarachele.it");
navigateToURL(url, "_blank");
}

I used this code but does not work, nothing happens, why?

Thanks.

Link to comment
Share on other sites

Here's a problem:

 

marchi01.annarachele.addEventListener(MouseEvent.MOUSE_OVER, pausa);
function pausa(event:MouseEvent):void {
loghi1.pause();
loghi2.pause();
}
marchi01.annarachele.addEventListener(MouseEvent.MOUSE_OVER, riprendi);
function riprendi(event:MouseEvent):void {
loghi1.resume();
loghi2.resume();
}

 

You have two MOUSE_OVER listeners on the same object, one that pauses the tweens and one that resumes them! So both fire immediately (pauses, then resumes). I think you meant to add a ROLL_OVER and a ROLL_OUT instead, right?

Link to comment
Share on other sites

  • 6 years later...

sorry. you can delete this message )

the problem was with 

getTweensOf(mc, true); flag.

 

all paused tweens are not active!.

 

 

 

 

 

 

 

 

 

 

////////////// question just for archive.

 

but let me take it straight

var tm:TweenMax = TweenMax.from(mc, duration, obj);
tm.pause();

then I forget about this tween for a little while.

then I come back and do

 

var tweensarr:Array = TweenMax.getTweensOf(mc, true);
trace("currently " + tweensarr.length + " tweens");
for each(var tweenToContinue:TweenMax in tweensarr) {
    trace("___________________ there s tween to continue " + tweenToContinue);
    tweenToContinue.play();
}

currently always 0 tweens.

that's why no tweens got continued.

 

Can you help me? Is this behaviour familiar?

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...