Flash help loading from textfile

  • Thread starter Thread starter sid_galt
  • Start date Start date
  • Tags Tags
    Flash
Click For Summary

Discussion Overview

The discussion revolves around loading content from a text file into a popup window in Flash, specifically focusing on how to create links or buttons within that content that can load additional SWF files at different levels without replacing existing content. The scope includes technical implementation and potential limitations of Flash's capabilities.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

Areas of Agreement / Disagreement

Participants express differing views on the feasibility and complexity of implementing links within Flash, with some suggesting possible solutions while others raise concerns about limitations and the need for additional components or methods.

Contextual Notes

Limitations include the inability of Flash text fields to support full HTML functionality, which may restrict how links are displayed and interacted with. The discussion also highlights the need for careful consideration of button positioning and dynamic content generation.

sid_galt
Messages
503
Reaction score
1
So i have made a tutorial in which a popup window appears and draws content from a variable stored in a textfield. The base swf is at level 0. On that swf there appears an swf at level 1. and the popup window is at level 2.

What I want is that inside the content loaded from the textfile into the popup window, there should be links or buttons that open up a further swf file at level 2 or higher so as to not replace the previous two levels.

Is it possible to do so in Flash?
 
Technology news on Phys.org
can anyone help please?
 
Let me get a clear idea of what you want to do. You want to load text from a text file into a pop up window, and in this text you want there to be "links" that load other movies into other levels. There's not anyfunctionality that will enable you to do this without some work, but you can do it if you really want to.
The first thing you will need to do is establish a format for your text files. You should use XML because it's easy to parse. An example XML file is:
Code:
<root>
<links>
<link ref="myswf.swf" level="3">A link</link>
<link ref="myswf2.swf" level="4">Another link</link>
</links>
<text>This is some text that you are loading into level 0, for some reason</text>
</root>

You would then use Flash's XML object to read in everything:
Code:
xmlObj = new XML();
xmlObj.ignoreWhite = true;
xmlObj.onLoad = function(success) {
	links = this.firstChild.childNodes[0].childNodes;
	for (i=0; i<links.length; i++) {
		link = new Object();
		link.ref = links[i].attributes.ref;
		link.level = links[i].attributes.level;
		link.text = links[i].firstChild.nodeValue;
		button = _root.createClassObject(mx.controls.Button, "b"+i, _root.getNextHighestDepth(), {label:link.text});
		button.move(100*i, 20*i);
		button.link = link;
		button.onPress = function() {
			loadMovieNum(this.link.ref, this.link.level);
		};
	}
	txt = this.firstChild.childNodes[1].firstChild.nodeValue;
	trace("Loaded text: "+txt);
};
xmlObj.load("myxml.xml");

The code above reads the XML file and creates a link Object storing the link's ref, level, and text fields. We then create an instance of the Flash Button component (this code will only work if you have an instance of a the flash button component in your library, just drag a button component into the stage to accomplish this) for each link. It sets the label on the button to the text corresponding to the link, and it sets the button so that, when it is pressed, loads the correct movie into the correct level. Of course you don't have to use the Flash Button Component, you can create just create an empty movie clip, create a textField inside it and use that as a button, but you get the idea.

BTW: the code works.
 
Last edited:
Thanks.

One point I would like to clarify - since we have to build a button for each link, does that mean that we have to know the number of links we have in advance?
 
That depends on how you want to position the buttons in the page. Right now the code i posted just throws them in there.
I can imagine that you probably want your links to be all text and displayed as in an HTML page but this would not be very easy. It could get quite complicated. It would be doable if the flas's text fields supported the HTML tag <a>, but they don't, they only support text formatting tags. Unless you can find a flash component that does this i wouldn't go for it. On the other hand i think such a flash component would be pretty popular and i think i'll try to make one when i have the time.
 
flash 7 up does support <a> tags only they support only the href attribute. No other attributes
 
I tried it with flash 8 and it didn't fly. But if that's the case, then you can do it by using Flash-Javascript integration. Basically your "link" would be a call to a javascript function in the same page as the flash movie which calls a function in the flash movie which is responsible for loading a movie into a lvel. This may seem a little ridiculous because you're calling Javascript only to call a flash function, but it would save a lot of text parsing and calculations.
If your flash movie is for standalone use, then it's another story.

[edit] it does work with flash 8.
 
Last edited:

Similar threads

  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
11K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
9K
  • · Replies 23 ·
Replies
23
Views
5K
  • · Replies 2 ·
Replies
2
Views
9K