Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
One other issue I see is that at the scrolling looks kind of choppy and not smooth. Is there a way to fix that?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
You need to import the easing classes
import com.greensock.easing.*;
Copy link to clipboard
Copied
Thanks, that helps. However, the issue with the choppy or interlaced like motion is still there with the texts scrolling from right to left.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 textsfunction 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