Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to determine when the Tween is done?

Guest
Dec 03, 2009 Dec 03, 2009

I'm loading texts from an external file and horizontally scroll the texts accross the screen with the following tween:

slideXTween = new Tween(txtField, "x", None.easeNone, txtField.x, -txtField.x*3, 70, true);

How do I find out when the tween is done and start loading another external text file or show a static/dynamic movie clip on the screen?

Your help is appreciated.

TOPICS
ActionScript
936
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 03, 2009 Dec 03, 2009

the flash tween class has a motionFinish event that you can use.  add a listener for that event and in your listener function load your other text file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 03, 2009 Dec 03, 2009

FWIW - switch to TweenLite and ditch the included Tween classes... for one TweenLite is _much_ faster, and it's also a lot easier syntax wise. And with it you can use its onComplete parameter to just call a function when the tween is done. Seriously...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 04, 2009 Dec 04, 2009

Thanks! This is what I have so far.

TweenLite.to(txtField, 30, {x:-stage.stageWidth, ease:None.easeInOut, delay:0.5, onComplete:myFunction});
function myFunction():void {
    trace("tween finished");
}

A couple of things. One, how do I get the texts to scroll off the screen to the left? I use the -stage.stageWidth and it's not working. Second, it seems like even though I use ease:None.easeInOu the scroll from left to right is really slow at the end.

Help is appreciated.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 04, 2009 Dec 04, 2009

One other issue I see is that at the scrolling looks kind of choppy and not smooth. Is there a way to fix that?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 04, 2009 Dec 04, 2009

Not sure what None.easeInOut is from, but you should use the TweenLite easing class - and then it would be ease:Linear.easeNone

What do you get when you just trace -stage.stageWidth?

For your next question  - it being choppy - what is the frame rate of Flash set to? A good default is 30fps.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 07, 2009 Dec 07, 2009

I tried ease:Linear.easeNone I got this error:1120: Access of undefined property Linear.

trace("Stage Width: " + stage.stageWidth); I got 735.

Frame rate is set at: 30

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 07, 2009 Dec 07, 2009

You need to import the easing classes

import com.greensock.easing.*;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 07, 2009 Dec 07, 2009

Thanks, that helps. However, the issue with the choppy or interlaced like motion is still there with the texts scrolling from right to left.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 07, 2009 Dec 07, 2009

How many objects are you tweening? You've set your framerate to 30, but that doesn't mean you'll get 30 if the client computer can't handle the tweening. The frame rate could drop depending on the CPU capability and the quality setting you set when the swf loads.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 07, 2009 Dec 07, 2009
LATEST

Just one tween. My computer is Intel 2 Quad Core 2.4Ghz with 4GB of RAM. I'm pretty sure the computer is able to handle a less than 1MB swf file that runs 30fps.

Below is my full code:

//import classes
import com.greensock.TweenLite;
import com.greensock.easing.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;
//end of importing

//start of sound section is for sound
var soundReq:URLRequest=new URLRequest("PaukenBrumfiel_AngelsOnHigh.mp3");
var sound:Sound = new Sound();
sound.load(soundReq);
sound.addEventListener(Event.COMPLETE, onComplete);
//end of sound section

//Loading external texts
var weiss:Font = new Weiss();
var slideXTween:Tween;
var txtAlphaTween:Tween;
var txtNextText:Tween;
var txtContainer:Sprite;
var txtField:TextField = new TextField();
var textRequest:URLRequest=new URLRequest("happyHoliday.txt");
var textLoad:URLLoader = new URLLoader();
var txtFormat:TextFormat = new TextFormat();
//end of loading external texts

function onComplete(event:Event):void {
    sound.play();
}

function textReady(event:Event):void
{
    txtFormat.font = weiss.fontName;
    txtFormat.color = 0x000066;
    txtFormat.size = 24;
    //txtField.x = stage.stageWidth;
    //txtField.width = 800;
    txtField.autoSize = TextFieldAutoSize.LEFT;
    //txtField.height = txtField.autoSize
    txtField.wordWrap = false;
    txtField.text = event.target.data;
    txtField.setTextFormat(txtFormat);
    //txtField.y = 350;
    txtField.embedFonts = true;
}

//load external texts
textLoad.load(textRequest);
textLoad.addEventListener(Event.COMPLETE, textReady);
txtField.x = stage.stageWidth;
addChild(txtField);
trace("First txtField.y: " + txtField.y);
txtField.y = 350;
TweenLite.to(txtField, 40, {x:-stage.stageWidth*2.25, ease:Linear.easeNone, delay:0.5, onComplete:myFunction});
function myFunction():void {
    trace("Second txtField.y: " + txtField.y);
    textLoad.load(new URLRequest("inspiration.txt"));
    txtField.x = 150;
    txtField.y = 250;
    trace("Third txtField.y: " + txtField.y);
    txtField.alpha = 0;
    TweenLite.to(txtField, 5, {alpha:1, onComplete:nextText});
    //slideXTween = new Tween(txtField, "alpha", None.easeNone, 0, 1, 70, true);
    //TweenLite.to(txtField, 30, {x:-184, ease:None.easeInOut, delay:0.5, onComplete:nextText});
    //trace("tween finished");
    trace("Fourth txtField.y: " + txtField.y);
}
function nextText():void{
    trace("tween done");
}

//end of loading external texts

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines