1 Reply Latest reply on Jun 22, 2009 1:10 AM by Richard_Abbott

    Dynamically import text from Database- mx:Text

    hellsingfan Level 1

      Hello,

       

      I'm a total newbie to this area, and I've just started to learn Actionscript also, so excuse my ignorance

       

      I would like to create a site where basically the "content" (Text, saved in a .txt file) will be put into the mx:Text container.

       

      So for example currently I have a Panel and a mx:Text as a child. What I wanted to do was so that the text property would retrieve the text from a .txt file that I have saved on the computer. But I can't find a way that this can happen.

       

      My ultimate goal is that the text in the mx:Text is pulled from a database. Whichever link the user clicks, that text is retreived from the database. But since I'm beginning I just wanted to know how to get the text from a source file.

       

      Another problem I'm having is this: Currently I have like a paragraph inside the mx:Text and I want to make specific words mouseover. The only property I see is makes the WHOLE text as a mouseover. Is there a way to make "specific" words mouse over:

       

      For example if I have a mx:Text and the text property has the value "Hi my name is Hellsingfan" . How can i make the "hellsingfan" mouseover (not the whole sentence)?

       

      Thanks in advance

        • 1. Re: Dynamically import text from Database- mx:Text
          Richard_Abbott Level 3

          hellsingfan,

          You can certainly do the first of your options relatively easily, so long as the file in question is on the server and you write some server side script (in ASP, JSP, PHP or whatever) to access it. The Flex code then uses HTTPService to invoke the script page you want and decode the result. As a general principle it is easier to use XML than plain text, but either is possible. Using this way you will also be able easily to "upgrade" to a database call as and when you want, by simply changing the file access code to db access.

          It is not possible in Flex 3 to access a file on the client local file system. To do this, yuo would have to either use Flex 4, or else write an AIR application which a user would downlaod and install.

          To resolve the second problem will involve you writing a new ActionScript class. As you say, the mouseover action for the regular text component treats the whole thing as one. You would need to derive a class from Text (or whichever of the basic text components best suits your need) and then override the mouse handling to do whatever you wanted.

          You mentioned that you were a newbie as regards Flex/ActionScript... but I wasn't sure what other kinds of programming experience you have. Some of the stuff I have written above may sound trivial, or may sound intimidating depending on what other knowledge you have brought into Flex programming!

          Richard