#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    NYC
    Posts
    19
    Rep Power
    0

    Question PHP variables from MySQL -> Flash


    Hey all,
    I'm relatively new to actionscript (only about 3 months or so) but it's a great language that I'm trying my best to learn. Anyways, on to my situation:

    I'm attempting to create a PHP/MySQL news database with a Flash frontend for my friend's web site. I've been trying to follow this tutorial:

    http://actionscript-toolbox.com/samplemx_loadvars.php

    with a few modifications. I don't need visitors to click on a tab to load the news, I'd rather have the last 5 stories "pop-up" on the page when they arrive. I've gotten to the point where I've made a php page that outputs the data from MySQL into a string:

    http://www.daysendmusic.com/preview2003/new/news.php

    (don't ask how long that took... )

    Here's the source for it:

    Code:
    <?php 
    
    mysql_connect("localhost", "daysendm_author", "******");
    mysql_select_db("daysendm_news"); 
    
    $qr = @mysql_query("select authorName, authorEmail, body from news limit 5"); 
    
    $nrows = mysql_num_rows($qr);
    $rString = "n=".$nrows;
    
    for ($i=0; $i < $nrows; $i++) {
    	$row = mysql_fetch_array($qr);
    	$rString .= "&authorEmail".$i."=".$row['authorEmail'];
    	$rString .= "&authorName".$i."=".$row['authorName'];
    	$rString .= "&body".$i."=".$row['body'];
    }
    echo $rString;
    ?>

    Now the part that I'm stuck on is how to get that data to be displayed in Flash. Every time I try to access the information provided from news.php, nothing happens. No news is loaded into the news.swf file. I've tried accessing the news.php file and it does display the correct variables but that's as far as I've gotten. As stated above, I would simply like the last 5 stories presented in a scroll box with the author, a link to the author's e-mail, and the body of the news (I would also like to try and get the date working but I'll attempt that later).

    I've attached the .fla file so you can see how I've been working so far. All the action takes place inside the mc_main movie clip. Here's the code I'm trying to get working from the one of the action frames:

    Code:
    _root.main.newstextclip.newstext.htmlText = "Loading News";
    temp = new LoadVars();
    temp.onLoad = function() { 
    	for (i=0; i < this.n; i++) {
    		_root.main.newstextclip.newstext.htmlText += "<b><ahref='mailto:" + this["authorEmail"+i] + "'>" + this["authorName"+i] + "</a></b><br>";
    		_root.main.newstextclip.newstext.htmlText += "  " + this["body"+i] + "<br>";
    	}
    }
    temp.load("news.php");
    stop()
    You'll probably need to see the .fla file to make sense of everything. I would also like to note that this takes place on _level1 of a larger swf file that imports this news.swf to use.

    I've spent several days and many headaches trying to get this to work so if anyone could help me I would really, really appreciate it.


    Thanks!
    Attached Files
    Last edited by Tbone; March 21st, 2003 at 10:06 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    126
    Rep Power
    12
    So what exactly are you having problems with?????
    Last edited by JCMerlin; March 21st, 2003 at 09:35 PM.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    NYC
    Posts
    19
    Rep Power
    0
    Sorry, should've been more clear.

    The Flash part of the site doesn't seem to work. No news is displayed when the news.swf file is loaded. Nada. I can't quite get the code to work for the flash end.
    Last edited by Tbone; March 21st, 2003 at 10:06 PM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    126
    Rep Power
    12
    Ok, let me look at it in a while.. got some things i have to take care of but i promise ill get back to you asap.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    126
    Rep Power
    12
    your variables arent getting back to flash. Try this and if this doesnt work, then you know the problem lies in the flash part.

    PHP Code:
    $nrows mysql_num_rows($qr);
    $rString "&n=".$nrows// common mistake. start ALL of your echos back to flash with an ampersand.

    for ($i=0$i $nrows$i++) {
        
    $row mysql_fetch_array($qr);
        
    $rString .= "&authorEmail".$i."=".$row['authorEmail'];
        
    $rString .= "&authorName".$i."=".$row['authorName'];
        
    $rString .= "&body".$i."=".$row['body'];
    }
    echo 
    $rString
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    NYC
    Posts
    19
    Rep Power
    0
    Merlin,
    Thanks for the reply, I didn't notice I was missing an amperstand.

    I changed the php code but it still doesn't want to load so it must be on Flash's end. I was talking with someone else from another forum and they suggested changing the code in Flash to this:

    Code:
    for (i = 0 ; i < Number(temp.n) ; i++)
    {
            trace("i = " + i + " : " + temp["authorEmail"+i]);
            _root.main.newstextclip.newstext.htmlText += "<b><a href='mailto:" + temp["authorEmail"+i] + "'>" + temp["authorName"+i] + "</a></b>";
            _root.main.newstextclip.newstext.htmlText += "  " + temp["body"+i] + "";
    }
    Apparently because the data coming into Flash is a string, I have to use the Number() function to change it's type. I'm going to give that a try and I'll let you know if it does anything.

    Thanks for your help!
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    126
    Rep Power
    12
    hmmm.... thats a possibility, if you cant work that out try using eval ....

    PHP Code:
    for (Number(temp.n) ; i++)
    {
            
    trace("i = " " : " temp["authorEmail"+i]);
            
    _root.main.newstextclip.newstext.htmlText += "<b><a href='mailto:" + eval(temp["authorEmail"+i]) + "'>" + eval(temp["authorName"+i]) + "</a></b>";
            
    _root.main.newstextclip.newstext.htmlText += "  " + eval(temp["body"+i]) + "";

  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    126
    Rep Power
    12
    I got it working fine just like this.....

    PHP Code:
    _root.main.newstextclip.newstext.htmlText "Loading News";
    temp = new LoadVars();
    temp.onLoad = function() { 
        for (
    i=0this.ni++) {
            
    _root.main.newstextclip.newstext.htmlText += "<b><ahref='mailto:" this["authorEmail"+i] + "'>" this["authorName"+i] + "</a></b><br>";
            
    _root.main.newstextclip.newstext.htmlText += "&nbsp;&nbsp;" this["body"+i] + "<br>";
        }
    }
    temp.load("http://www.daysendmusic.com/preview2003/new/news.php ");
    stop() 
    Make sure that the <> icon is pressed on the dynamic text box.
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    NYC
    Posts
    19
    Rep Power
    0
    Got it working with that last bit of code! Thank you very much I really appreciate it. You're the man.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    126
    Rep Power
    12

IMN logo majestic logo threadwatch logo seochat tools logo