A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Dynamic text...or is it

Hybrid View

  1. #1
    Junior Member
    Join Date
    Feb 2003
    Posts
    5

    Dynamic text...or is it

    I saw a site a guy did about a year ago. His dynamic text boxes were not getting info from a txt file but were in fact getting the text and data from php and asp pages. No kind of special coding in the php or asp files but were created that way for extremely easy update using an update interface form that he created.

    How is this possible?

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    you just need to get your PHP or ASP script to write out variables (possibly the results of a database query or reading an external file etc) to the page as a urlencoded query string (like how you would type the text if you were just typing into a textfile for flash to load)

    eg for PHP,

    echo "&someVarName=" . urlencode($someVarName) . "&someOtherVar=" . urlencode($someOtherVar) . "&";

    when you use something like loadVariables to call the script that contains this flash will read back these variables into the timeline that called the loadVaraibles action.

  3. #3
    Junior Member
    Join Date
    Feb 2003
    Posts
    5

    Here is an example

    This is the result that showed up in a flash window:

    08/14/2002
    Datadatadatadatadata www.Data.com
    ::Editor::
    08/27/2001
    Another news entry www.data.com
    ::Admin::

    I aded the ASP file (Code in a text format) as an attachment. This seems very simple. How do you call it into the flash movie?
    Attached Files Attached Files

  4. #4
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    this.loadVariables("filename.asp");

    remove all the excess html code from the file though, flash can only read the string of variables (the stuff included in the <body> of the page)

    is there any reason why this needs to be ASP (or PHP for that matter) unless that information is being pulled from a database or being generated dynamically in some other way you may as well just type out the code and save it as a textfile.

  5. #5
    Junior Member
    Join Date
    Feb 2003
    Posts
    5
    The reason I am looking at doing it this way is for two reasons.

    1. Update time on Flash and Non flash sites will be decreased.

    2. Data updated dynamically through an updater form for non web developers that need to update news on page without use of a database.

  6. #6
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    again if this is the case I wouldn't load variables from the ASP file.
    instead you can create an ASP page with form fields for the user to fill in to update the content. this ASP page can then write the text file (I don't know much ASP, but I assume it can do this kind of stuff, certainly things like PHP can) you can then get flash to load the textfile created by the ASP page.

  7. #7
    Junior Member
    Join Date
    Feb 2003
    Posts
    5
    I guess I am going this rout because I am less familiar with it. Can you give me a demonstation on how this is done?

  8. #8
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    I don't know ASP well, but this code does the same thing in PHP

    to begin lets say your flash movie has 3 fields that need to be filled with dynamic text (flashVarName1, flashVarName2 and flashVarName3) to begin you can create an html form that can be used for whoever is updating the site (in the real world you'd proabably want to password protect this page so only people you want updating the site have access) use input fields appropriate to the content, for example textareas for fields where a lot of text is likely to be entered. here's an example

    <html>
    <head>
    <title>update flash content</title>
    </head>
    <body>
    <form method="post" action="writefile.php">
    <p>enter text for flashVarName1 here <input type="text" name="flashVarName1" /></p>
    <p>enter text for flashVarName2 here <input type="text" name="flashVarName2" /></p>
    <p>enter text for flashVarName3 here <textarea name="flashVarName3"></textarea></p>
    <p><input type="submit" value="update!" /></p>
    </form>
    </body>
    </html>

    when the form is submitted it gets sent to the page writefile.php which can create the textfile.

    PHP Code:
    <?php

    function writeText() {
        if (!
    $fp fopen('data.txt''w')) { // attempt to open a file, data.txt for writing if it doesn't exist try to create it
            
    return 'fail'// it hasn't worked
        
    }
        
    // create a variable containing a urlencoded query string of the variables to be loaded into flash
        
    $content '&flashVarName1=' urlencode($_POST['flashVarName1']);
        
    $content .= '&flashVarName2=' urlencode($_POST['flashVarName2']);
        
    $content .= '&flashVarName3=' urlencode($_POST['flashVarName3']) . '&';
        
    fwrite($fp$content); // write the content to the file (overwrites existing content)
        
    fclose($fp); // close the file
        
    return 'okay';
    }

    $result writeText();
    if (
    $result == 'okay') {
        echo 
    "thanks for updating the site content";
    } else {
        echo 
    "there was an error, please <a href=\"javascript:history.go(-1);\">click here to go back</a>";
    }

    ?>
    in flash you can now load the file data.txt to get at the content

    instanceName.loadVariables("data.txt");

  9. #9
    Member
    Join Date
    Jan 2003
    Location
    Lancaster, PA
    Posts
    85

    displaying the text

    how do I get the text to display in flash, though?

  10. #10
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    You can use the loadvars object to load the text from a file and display it in your movie,

    for example the following would load file named filename.txt (containing a variable named myVariable) and display this variable in a textfield with the instance name myText,

    Code:
    var lv = new LoadVars();
    lv.onLoad = function(ok) {
        if (ok) {
            myText.text = this.myVariable;
        }
    };
    lv.load("filename.txt");

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