A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: Setting dynamic text from within a webpage without using a text file

  1. #1
    Junior Member
    Join Date
    Nov 2007
    Posts
    8

    Setting dynamic text from within a webpage without using a text file

    As a complete newbie to flash and KoolMoves, I am having some difficulty with what would seem to be a simple task.

    All I wish to do is to have an SWF with a single, dynamic-text field that I could set via javascript using HTML text retrieved from a mySQL database with PHP. By doing this, I am hoping to make it more difficult for someone to steal text from a website by simple copy/paste or source-code methods.

    This needs to be truly dynamic, without the use of a text file containing values for LoadVars, but most of the tutorials I am encountering want to use text files.

    I have tried the javascript-related instructions in the "Dynamic Text in Kool Moves 3.doc" tutorial file from the KoolMoves site, but in Firefox, the javascript console shows the following error: "window.document.movie has no properties" and in IE, it gets the following error: "'window.document.movie' is null or not an object" and the text does not change.

    Ultimately, I WAS able to pass SOMEthing to the dynamic text field in that example, but only by coding it into the URL used to load the movie (i.e. "?text=whatever").

    To summarise, I want:
    • to have a single, dynamic-text field, with HTML enabled, but text-selection, etc., disabled
    • to use PHP/mySQL to retrieve the text to be fed to the dynamic-text field
    • to set the value of the dynamic-text field without using a text file, and without having the text visible in the page source code
    Thanks!

    Oops! Forgot to add the version info, etc., in case it matters. This was with KoolMoves 6.2.0, and was tested with Firefox 2.0.0.9 and IE 7.0.5730.11, with ShockWave player 10.1r21.
    Last edited by Tsume; 11-30-2007 at 12:27 PM. Reason: Forgot version info

  2. #2
    Senior Member
    Join Date
    Jun 2000
    Posts
    3,512
    Until someone else replies with a specific answer to this database question, I suggest looking at www.koolexchange.com for an example.

  3. #3
    Junior Member
    Join Date
    Nov 2007
    Posts
    8
    Quote Originally Posted by Bob Hartzell
    Until someone else replies with a specific answer to this database question, I suggest looking at www.koolexchange.com for an example.
    Already have. That's what led to my question, and why I said, "I have tried the javascript-related instructions in the "Dynamic Text in Kool Moves 3.doc" tutorial file from the KoolMoves site."

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    you can send variables to flash via javascript, I can't look it up right now but search this forum. I'm pretty sure we covered this some time ago.

    If you're using PHP and MySql look at the numerous database example for getting data into/outof flash... Guestbooks etc. Basically call the PHP Code in the loadVars and you can either have the PHP send it as &varname= format or just raw and retrieve it in the loadVars.onData event.

  5. #5
    Junior Member
    Join Date
    Nov 2007
    Posts
    8
    Quote Originally Posted by blanius
    you can send variables to flash via javascript, I can't look it up right now but search this forum. I'm pretty sure we covered this some time ago.
    Absolutely, it was covered numerous times, and every one of those examples I have tried has failed. That is why I asked my question.

    If you're using PHP and MySql look at the numerous database example for getting data into/outof flash... Guestbooks etc. Basically call the PHP Code in the loadVars and you can either have the PHP send it as &varname= format or just raw and retrieve it in the loadVars.onData event.
    The PHP/mySQL part of it is not a problem. I can do that. It's how to get that information into the flash. All the examples I have seen that do NOT use loadvars have not worked, and the examples that I have seen that DO use loadvars all refer to reading a text file, and I do not wish to create a text file for the results of each query - it should not be necessary.

    Is there, perhaps, something I am missing about loadvars(), itself? Is that also used when passing values from javascript, etc., or only when using a text file? If it IS supposed to be used for javascript, why is it not mentioned in any of the "Dynamic Text in Kool Moves" DOC files?

    Although I am very experienced in other aspects of programming, I am completely new to flash and to KoolMoves, so when you say "retrieve it in the loadVars.onData event," that means nothing to me unless there is a concrete example to go along with it.

    Thanks.

  6. #6
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    LoadVars is not used for interacting with javascript but for loading data from a textfile. Since a php file querying a database can output text there is no difference. Instead of a textfile you can specify a php file that generates the required output (text) at runtime so you have no static textfile.

    If you want to interact with javascript, ExternalInterface is the way to do it.

  7. #7
    That web bloke Stoke Laurie's Avatar
    Join Date
    Jan 2006
    Location
    England
    Posts
    869
    The answer is very simple, take a look at the example in Koolexchange, by chris seahorn which sends an e-mail from a form. Take a look at the php, which writes to a text file. Use your php to write to a text file on your query, and then flash can take this value into your dynamic text box.

  8. #8
    Junior Member
    Join Date
    Nov 2007
    Posts
    8
    Quote Originally Posted by w.brants
    Instead of a textfile you can specify a php file that generates the required output (text) at runtime so you have no static textfile.
    Are you saying that the file used by loadvars can be a PHP file that will perform the queries, etc. at runtime and pass them to loadvars directly, or must the PHP file write to a text file first (which I've already stated I do not wish to do)?

    If I understand you properly, then the PHP file would echo or print the results as a variable statement ("myHTMLdata=blah blah blah") without sending it to some other text file, and loarvars would pick it up because the server, seeing the PHP file, would execute it at runtime. Is that correct?

    If you want to interact with javascript, ExternalInterface is the way to do it.
    Again, I'm completely new to flash, so terms like "ExternalInterface" mean nothing to me without concrete examples.

  9. #9
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Quote Originally Posted by Tsume
    If I understand you properly, then the PHP file would echo or print the results as a variable statement ("myHTMLdata=blah blah blah") without sending it to some other text file, and loarvars would pick it up because the server, seeing the PHP file, would execute it at runtime. Is that correct?
    Yes, that's correct and the easiest way to do it.

  10. #10
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Ok
    Example

    File:
    Attached Files Attached Files

  11. #11
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Get PHP generated Image from PHP into Flash movie?
    http://bretlanius.com/flash/gdtest.html

  12. #12
    Junior Member
    Join Date
    Nov 2007
    Posts
    8
    Quote Originally Posted by blanius
    Ok
    Example

    File:
    Sorry for taking so long to get back to this, but I've been working on other people's computers for a few days.

    Thanks for all the responses. The earlier suggestions helped, but until I saw the action script used in this example, it still wasn't working. I had just been missing a few things.

    For one, the set of four .DOC files that are on the KoolMoves website as a dynamic-text tutorial do not show ANY action scripts, so it makes it seem as though action scripts are not necessary to do this. In fact, it's not until the very END of the LAST of those files (one which deals with form creation - not what I was trying to do) that it says:
    Action scripting, not yet available in KM 2.60a but which will be made available in future releases above 2.60a are a preferred method of using Advanced Javascript and FS Commands as a work around.
    In other words, it's no wonder the tutorial fell short: it's FOUR versions behind! LOL!

    Also, I had not been using the variable assignment properly, since all the things I had seen were most emphatic in saying never to use the object name, but always to use the variable name. Thus, I had been trying to use "txtvar1" instead of "txt1."

    Of course, since I wanted to display HTML text, I had to change "txt1.text" to "txt1.HTMLtext" in your example, but that was simple enough to see.

    So, it DOES work now, thanks to the help I received from each of you.

  13. #13
    Junior Member
    Join Date
    Nov 2007
    Posts
    8
    Well, now I have a DIFFERENT problem. I AM able to get the dynamic text into the flash object, but that is now based upon a STATIC php file. It is "myHTML.php" in the posted example, but "myHTML.php" (or whatever would be placed within the flash object) doesn't appear to have any access to having anything passed to IT. In other words, if I want the dynamic text to be the description of a widget, retrieved from mySQL, there doesn't appear to be a way to pass that to the "myHTML.php" script.

    Thanks again!

    P.S.: I had started to edit my original post so I wouldn't be double posting, but got called away for a long phone call, and the system wouldn't let me complete the edit.
    Last edited by Tsume; 12-04-2007 at 08:58 PM. Reason: misspelling

  14. #14
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    I'm guessing that what you mean is that you want to SEND and LOAD variables.. i.e. Flash sends the PHP a variable so that the PHP can use that info to query the Database.

    two approaches, first is a simple one just build your loadVars.Load with the variable appended

    widget=2
    myData.loadVars("myMySql.php?widget="+widget)

    The you should get $_POST[widget] that equals 2 in your PHP

    They fully loadVars method is to use LoadAndSend.
    I don't have code in front of me at the moment but basically you build 2 loadVars and you send one and load the other in the same process.

    There are examples on the Adobe site. See my sig for the link. Note that most of the example code is AS2 and so needs a little tweeking mainly removing the colon vartype i.e.

    myData:loadvars = new LoadVars would be
    myData= new LoadVars

    widget:STRING=2 would be
    widget =2

    etc..

  15. #15
    Junior Member
    Join Date
    Nov 2007
    Posts
    8
    Quote Originally Posted by blanius
    two approaches, first is a simple one just build your loadVars.Load with the variable appended

    widget=2
    myData.loadVars("myMySql.php?widget="+widget)

    The you should get $_POST[widget] that equals 2 in your PHP
    I still can't see how that would work, since the variables are coming from ANOTHER PHP script. The scenario is something like this:
    1. Visitor is one a page containing thumbnails and captions (which are links) of several widgets.
    2. Visitor clicks on the link for a specific widget, and the widget number is passed to a different PHP file via "?ID=xxx" (with "xxx" being the actual ID number of the selected widget).
    3. The PHP file that displays the information for the specific widget receives the widget ID from the URL, as mentioned above, then uses that to query the database to read the complete, detailed, HTML description of the widget.
    4. THAT description is what I want to pass to the flash object.
    I'll keep trying some different ideas, but maybe the above scenario will help to clarify things.

    Thanks again!

  16. #16
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    I guess I'm not understanding what you're not quite getting. You can pass data back and forth all you want via loadVars the great thing about using loadVars over other methods is that it has events like OnData and OnLoad.

    Flash calls PHP that querys database and sends list of widgets. WHen that data arrives you display the list of widgets in a listbox, as movieclips or whatever. These have code that uses the variables from the first query and sends additional call to loadVars that retreives description.

    If the data is not too large you could also just load the whole thing including descriptions and build that into Arrays. Then you only have to query once.

    I just don't have the time for a demo right now sorry.

  17. #17
    That web bloke Stoke Laurie's Avatar
    Join Date
    Jan 2006
    Location
    England
    Posts
    869
    Not sure if you have seen this, but if you take a look here http://board.flashkit.com/board/showthread.php?t=749364
    If you want, you can adapt it to transfer information from MySQL via php to vertually any format you want.

  18. #18
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Ok heres a quick example

    I don't promise to keep the PHP online forever so here's the PHP code
    PHP Code:
    <?php 

    if ($_GET['cmd']=="list"){
        echo (
    "car|1\nhouse|2");
        }
        
    if (
    $_GET['cmd']=="id"){
        if (
    $_GET['id']==1){
            echo (
    "A four wheeled Vehicle");
            }
        else if (
    $_GET['id']==2){
            echo (
    "A place where people live");
            }
        else{
            echo (
    "I could not find your request");
            }
        }
    ?>
    Here's the fun file

    and link to example

    http://bretlanius.com/flash/dataexample.html
    Attached Files Attached Files

  19. #19
    Junior Member
    Join Date
    Nov 2007
    Posts
    8
    Thanks for the further answers. I'll take a look at this over the weekend.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center