Flash help loading from textfile

  • Thread starter Thread starter sid_galt
  • Start date Start date
  • Tags Tags
    Flash
AI Thread Summary
A tutorial was created to implement a popup window in Flash that loads content from a text file, with the goal of including links or buttons that can load additional SWF files at higher levels without replacing existing content. The discussion emphasizes the use of XML for structuring the text file, which simplifies parsing and allows for dynamic link creation. The provided code demonstrates how to read the XML, create button instances for each link, and set up their functionality to load the corresponding SWF files. It is noted that while the current implementation positions buttons based on a fixed layout, flexibility in button placement may require knowing the number of links in advance. The limitations of Flash's text fields regarding HTML support are discussed, with suggestions for using Flash-JavaScript integration for more complex link functionality. The conversation concludes with confirmation that the code works as intended.
sid_galt
Messages
502
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 alot 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:
Back
Top