A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: need help to loop/repeat text in dynamic text field

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    11

    need help to loop/repeat text in dynamic text field

    I've been working on a site that wants a dash of content management for its biographies page. I've been successful in getting the SQL database to write to the PHP and then Flash reads it in quite well. The loop in PHP works and sends all the data from the table to PHP and then on to Flash.

    However, my problem lies in my ability to take one single dynamic text box and punch out the formatting and biographies like so:

    Name: Mike Jones
    Biography: I come from Oklahama, etc.

    Name: Billy Joe
    Biography: I come from Illinois, etc.

    I have a loop properly set that kicks out the formatting, but only loops (so far) the single variable over and over again. I've tried putting [i] after the "myData.emName[i]" like so, but it returns as undefined. I also need a way of making my while loop terminate properly (right now, you'll see, it has the number 3 just for testing purposes, but there has to be some way of getting it to only print out how many rows there are in the SQL database, etc). I need desperate help before the week (preferably day) is out.

    Here is my actionscript code for my file. It's just a test file so it's pretty stripped down:

    myData = new LoadVars();
    myData.onLoad = function() {
    placeData();
    }
    myData.load("test.php");

    placeData = function() {
    var i=0;
    while (i<3) {
    bioBox.htmlText += "<b>Name: </b> + myData.emName1 + "<br><b>Biography: </b>" + myData.desc1 + "<br><br>";
    i++;
    }
    }

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe try something like this...

    Code:
    myData = new LoadVars();
    myData.onLoad = function() {
    	placeData();
    };
    myData.load("test.php");
    placeData = function () {
    	var i = 0;
    	while (myData["emName"+i] != undefined) {
    		bioBox.htmlText += "<b>Name: </b>" + myData["emName"+i] + "<br><b>Biography: </b>" + myData["desc"+i] + "<br><br>";
    		i++;
    	}
    };

  3. #3
    Junior Member
    Join Date
    Jan 2008
    Posts
    11
    No such luck... sorry

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Can you post test.php file you are using?

  5. #5
    Junior Member
    Join Date
    Jan 2008
    Posts
    11
    <?php
    $dbhost = 'host';
    $dbuser = 'user';
    $dbpass = 'pass';

    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

    $dbname = 'database';
    mysql_select_db($dbname);

    $query = "SELECT employee, bioText, id FROM bio";
    $result = mysql_query($query);

    while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
    echo "&emName{$row['id']}={$row['employee']}&desc{$row['id']}={$row['bioText']}";
    }

    ?>

  6. #6
    :
    Join Date
    Dec 2002
    Posts
    3,518
    What to you get for an output from this trace?
    Code:
    myData = new LoadVars();
    myData.onLoad = function() {
    	trace(this.toString());
    	placeData();
    };
    myData.load("test.php");
    placeData = function () {
    	var i = 0;
    	while (myData["emName"+i] != undefined) {
    		bioBox.htmlText += "<b>Name: </b>" + myData["emName"+i] + "<br><b>Biography: </b>" + myData["desc"+i] + "<br><br>";
    		i++;
    	}
    };

  7. #7
    Junior Member
    Join Date
    Jan 2008
    Posts
    11
    It comes back with a bunch of garbage with pieces of the PHP script intermingled like variables and connection strings, etc.

  8. #8
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Yes, but are you seeing "emName0=" within the output?

    Basically the script posted is looking for the variables 'emName0' 'desc0', 'emName1', 'desc1', 'emName2', 'desc2', etc. If the variables aren't there with the sequence numbers this script won't work.

  9. #9
    Junior Member
    Join Date
    Jan 2008
    Posts
    11
    my SQL table starts incrementing at 1 so the ID doesn't ever get to 0. This would break up the script, correct?

  10. #10
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Yes!
    Code:
    myData = new LoadVars();
    myData.onLoad = function() {
    	placeData();
    };
    myData.load("test.php");
    placeData = function () {
    	var i = 1;
    	while (myData["emName"+i] != undefined) {
    		bioBox.htmlText += "<b>Name: </b>" + myData["emName"+i] + "<br><b>Biography: </b>" + myData["desc"+i] + "<br><br>";
    		i++;
    	}
    };

  11. #11
    Junior Member
    Join Date
    Jan 2008
    Posts
    11
    My friend... it works beautifully. Thank you so very much. If you were here in the Peoria area, I would buy you a drink.

  12. #12
    Junior Member
    Join Date
    May 2008
    Posts
    3

    help me~!

    so Happy to see this post~!
    i need it urgent...
    May i know....is it possible to click each,then will run"gotoandplay" to specified frame?
    I am new in flash and it made me headache!

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