8 Replies Latest reply on Jul 13, 2007 5:36 PM by tyler_nelson

    load text into flash

    tyler_nelson Level 1
      I want a dynamic text field that loads different text files depending on what button is clicked. In xml each node defines what text file to load. What would be the actionscript code to load the text files?

      Here is what my xml file looks like:

        • 1. Re: load text into flash
          Greg Dove Level 4
          Depends what you've already done. You didn't say you had problems getting the xml into flash etc. So I'll assume you have the icon nodes in an array... and perhaps you've loaded the icon images into the buttons or used the tooptip attributes for your tooltips for the buttons?.

          If you've done that then you already know how to retrieve the icon node attributes and you just need to use a LoadVars to load your text file content. LoadVars works similarly to the XML object, so shouldn't be too difficult if you've already got that working well.

          If you want raw text from your text files then access it in the LoadVars onData handler (after assigning a listener in much the same way you do for the XML). If its in urlencoded name=value&name=value etc pairs then you can access the "name" properties from the LoadVars instance after the onLoad handler has run.

          • 2. Re: load text into flash
            tyler_nelson Level 1
            i have already loaded the xml file correctly. i have defined the tooltips, and images. i do know how to load a text file by itself with the loadVars function. i just dont know how to have the xml file tell the loadVars which text file to load. the text file is urlencoded: content=... and &projects=...
            • 3. Re: load text into flash
              Greg Dove Level 4
              Just to clarify:
              Do you want all the individual textfiles loaded after the xml has loaded... or do you want each button press to load that button's textfile?

              If its the buttons... then you just need some way to associate the onPress event with the content attribute from the same icon Node you used for the other things.

              When you create the buttons you could assign a content property directly to the button which is the value of the content attribute... that way each button can access the associated textfile content filename in its onPress handler... I haven't tested this but I'm pretty sure it would work.
              It would mean that the load command is being issued everytime the button is pressed though.
              var myLoadVars:LoadVars = new LoadVars()
              var my_lvlistener= {}
              my_lvlistener.onLoad = function(success) {
              //do whatever

              eachButtonInstance.onPress = function() {
              • 4. Re: load text into flash
                tyler_nelson Level 1
                the whole file is a carousel, much like the one on gotoandlearn.net. so the "buttons" are the images in the xml file, and when each image is clicked i want the text file to load. so, i dont think there are button instances.
                • 5. Re: load text into flash
                  Greg Dove Level 4
                  OK... -well they're like single-frame movieclips then and they can work like a movieclip... with an onPress handler. You could assign the value of the text url to each one in the onLoadInit handler if you're using the MovieClipLoader class to load them.

                  • 6. Re: load text into flash
                    tyler_nelson Level 1
                    im sorry, im really new to actionscript. what would be the code for this?
                    • 7. load text into flash
                      Greg Dove Level 4
                      Well this is a little different to what I was suggesting... I was suggesting it that way because you're already got the xml part working ... this way is pulling the index out of the icon clip name's to reuse it for array access to get the correct textfile name attribute (I haven't tested this... so I can't say for sure it will work..I think it should .but if not it should give you a start).

                      • 8. Re: load text into flash
                        tyler_nelson Level 1
                        I have been trying to figure out how to use the code you suggested for days now without luck. Maybe you can help me.
                        Inside the actual text files the content i want to display is after:

                        Here is the code i have for the whole carousel: