Skip to main content
December 4, 2009
Answered

How to load additional external texts?

  • December 4, 2009
  • 1 reply
  • 624 views

This is my external texts loading:

//Loading external texts
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

How do I utilize this same code for loading a second .txt file after the first one is loaded and the motion tween is completed? I don't want to rewrite this whole code for additional files to be loaded.

Thanks for any help.

This topic has been closed for replies.
Correct answer kglad

use:


TweenLite.to(txtField, 30, {x:-stage.stageWidth*2.25, ease:None.easeInOut, delay:0.5, onComplete:myFunction});
function myFunction():void {
   textLoad.load(new URLRequest("inspiration.txt"));
    TweenLite.to(txtField, 30, {x:-stage.stageWidth, ease:None.easeInOut, delay:0.5, onComplete:nextText});
    trace("tween finished");
}
function nextText():void{
    trace("tween done");
}


1 reply

kglad
Community Expert
Community Expert
December 4, 2009

the Tween class has a motionFinish event you can use to define a new urlrequest.  use that new urlrequest in another load method of your urlloader.

December 4, 2009

Okay, here's what I have:

TweenLite.to(txtField, 30, {x:-stage.stageWidth*2.25, ease:None.easeInOut, delay:0.5, onComplete:myFunction});
function myFunction():void {
    textRequest.load(new URLRequest("inspiration.txt"));
    TweenLite.to(txtField, 30, {x:-stage.stageWidth, ease:None.easeInOut, delay:0.5, onComplete:nextText});
    trace("tween finished");
}
function nextText():void{
    trace("tween done");
}

And here's the compiled error:

1061: Call to a possibly undefined method load through a reference with static type flash.net:URLRequest.

The error is referring to my second time loading the inspiration.txt file.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
December 4, 2009

use:


TweenLite.to(txtField, 30, {x:-stage.stageWidth*2.25, ease:None.easeInOut, delay:0.5, onComplete:myFunction});
function myFunction():void {
   textLoad.load(new URLRequest("inspiration.txt"));
    TweenLite.to(txtField, 30, {x:-stage.stageWidth, ease:None.easeInOut, delay:0.5, onComplete:nextText});
    trace("tween finished");
}
function nextText():void{
    trace("tween done");
}