Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Flash help loading from textfile

  1. Mar 12, 2006 #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?
     
  2. jcsd
  3. Mar 12, 2006 #2
    can anyone help please?
     
  4. Mar 12, 2006 #3

    -Job-

    User Avatar
    Science Advisor

    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 (Text):

    <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 (Text):

    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: Mar 12, 2006
  5. Mar 12, 2006 #4
    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?
     
  6. Mar 12, 2006 #5

    -Job-

    User Avatar
    Science Advisor

    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.
     
  7. Mar 12, 2006 #6
    flash 7 up does support <a> tags only they support only the href attribute. No other attributes
     
  8. Mar 12, 2006 #7

    -Job-

    User Avatar
    Science Advisor

    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: Mar 12, 2006
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Flash help loading from textfile
  1. XHTML (Flash) (Replies: 2)

Loading...