Skip to main content
Known Participant
October 3, 2009
Answered

Load Multiple Dynamic Text Files in Different frames on Maintimeline

  • October 3, 2009
  • 2 replies
  • 1532 views

Hello!

I have managed to load an external text file in one place one the maintimeline. I would like to do the same thing on other frames. When I go to duplicate the same thing that I did on the first one I get a duplicate textReq request. Do I need to give the textReq a more specific name for each section? When I did this the movie wouldn't even recognize and of the code that was working before.

Can anyone help me with this code? Thanks in advance

I am attaching link so you can see sections I am talking about. Also you will notice that the swf file I loaded won't go away. That's another problem...ugh.

Here is link:

http://www.sandraschmitt.com/coclico/index100.html

Here is code on maintimeline:

stop();

import fl.transitions.*;
import fl.transitions.easing.*;

import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;

function startLoad() {
    var swfLoader:Loader = new Loader();
    var swfRequest:URLRequest = new URLRequest("endlessCoclico3.swf");
    swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
    swfLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
    swfLoader.load(swfRequest);
}

function onCompleteHandler(loadEvent:Event) {
    addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(swfProgress:ProgressEvent) {
    var percent:Number = swfProgress.bytesLoaded/swfProgress.bytesTotal;
    trace(percent);
}
startLoad();

//handle events for buttons...
collections.addEventListener(MouseEvent.CLICK, clickSection);
raison.addEventListener(MouseEvent.CLICK, clickSection);
stores.addEventListener(MouseEvent.CLICK, clickSection);
news.addEventListener(MouseEvent.CLICK, clickSection);
contact.addEventListener(MouseEvent.CLICK, clickSection);
home.addEventListener(MouseEvent.CLICK, clickSection);


function clickSection(evtObj:MouseEvent) {
    //trace shows what's happening... in the output window
    trace("The "+evtObj.target.name+" button was clicked!");
    //go to the section clicked on...
    gotoAndStop(evtObj.target.name);
}


Here is code on actual frame where the dynamic text is working:

//Loaded exteranl text fields
var textLoader:URLLoader = new URLLoader();
var textReq:URLRequest = new URLRequest("text_philosophy.txt");

function textLoaded(event:Event):void {
    philosophy_txt.text = textLoader.data;
}

textLoader.load(textReq);
textLoader.addEventListener(Event.COMPLETE, textLoaded);

This topic has been closed for replies.
Correct answer Ned Murphy

Textfields:  What I like to do, mainly for peace of mind, is to have a layer that I dedicate to actionscript that only has code in frame 1 but it extends the full length of the timeline so that this code is available to every frame on any other layer.  In this frame I put variables and functions that can get used/shared wherever they happen to be needed.  I usually create another separate layer for actions types of actionscript... stuff that happens at the local frame level, like stop();, or like assigning a variable a new value, etc... things local to being at that frame/location.  So with that in mind

In frame 1 on my shared-by-everyone layer, I'd probably declare the variable....

var textReq:URLRequest;

And when I get to a particular frame where I want to load a new textfield with data, I assign that var its value on the local actions layer...

textReq = new URLRequest("text_philosophy.txt");

along with the rest of the local execution regarding loading the file, etc...

---------------------------------------

SWF's:

Yeah, pretty much, and it becomes an object that has a home on the timeline, so if you move away from that frame the swf doesn't follow.

2 replies

Participant
September 30, 2010

That was a great tip.

Ned Murphy
Legend
October 3, 2009

If you are redeclaring the var textReq (meaning you use var textReq multiple times) that will lead to a namespace/duplication error.  What you can probably do if you have a code layer that is accessible to all frames is to declare the variable just once in the first frame, and then assign it new values as needed.

If I'm not addressing the problem, I'm missing what it is.

As far as the swf not going away, when you dynamically load things, if they are not loaded into a container that has a home on the timeline, such as an empty movieclip, then they have no home on the timeline and will remain present when you move around.  Since I think you load your text into a textfield that has a home on the timeline, you should be able to understand the difference.  The text is added to a fixed timeline object.  The swf is not.

Known Participant
October 3, 2009

That is precisely what the problem is on both subjects. I am just confused where the code goes. I know in a perfect world all of my code would be on my first frame, but unfortunately it is not.

For the duplication of the text request in theory I get what you are saying and I have found some really helpful tutorials that along with these great forums I have gotten where I am. But they call the instances and variables different names and that along with the handler, events, etc names that I am not really familiar with... confuses me. I know I have taken a of of your time and I appreciate all your help. If you have a sample of what the syntax for this code would be that would be great. If not I understand

As far as the swf loader that makes sense and I made a container for a thumbnail gallery tutorial that I did. I didn't really realize why until now. If I load the swf. in to a container/mc then the container makes it an object I can control... correct?

thanks!!

sandra

Ned Murphy
Ned MurphyCorrect answer
Legend
October 3, 2009

Textfields:  What I like to do, mainly for peace of mind, is to have a layer that I dedicate to actionscript that only has code in frame 1 but it extends the full length of the timeline so that this code is available to every frame on any other layer.  In this frame I put variables and functions that can get used/shared wherever they happen to be needed.  I usually create another separate layer for actions types of actionscript... stuff that happens at the local frame level, like stop();, or like assigning a variable a new value, etc... things local to being at that frame/location.  So with that in mind

In frame 1 on my shared-by-everyone layer, I'd probably declare the variable....

var textReq:URLRequest;

And when I get to a particular frame where I want to load a new textfield with data, I assign that var its value on the local actions layer...

textReq = new URLRequest("text_philosophy.txt");

along with the rest of the local execution regarding loading the file, etc...

---------------------------------------

SWF's:

Yeah, pretty much, and it becomes an object that has a home on the timeline, so if you move away from that frame the swf doesn't follow.