Flash Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignFlash Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 21st, 2003, 08:48 PM
Tbone Tbone is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: NYC
Posts: 19 Tbone User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Tbone
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
File Type: zip news.zip (27.9 KB, 403 views)

Last edited by Tbone : March 21st, 2003 at 10:06 PM.

Reply With Quote
  #2  
Old March 21st, 2003, 09:29 PM
JCMerlin JCMerlin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 126 JCMerlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 29 sec
Reputation Power: 6
So what exactly are you having problems with?????

Last edited by JCMerlin : March 21st, 2003 at 09:35 PM.

Reply With Quote
  #3  
Old March 21st, 2003, 10:01 PM
Tbone Tbone is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: NYC
Posts: 19 Tbone User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Tbone
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.

Reply With Quote
  #4  
Old March 21st, 2003, 10:41 PM
JCMerlin JCMerlin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 126 JCMerlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 29 sec
Reputation Power: 6
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.

Reply With Quote
  #5  
Old March 22nd, 2003, 03:33 AM
JCMerlin JCMerlin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 126 JCMerlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 29 sec
Reputation Power: 6
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

Reply With Quote
  #6  
Old March 22nd, 2003, 12:00 PM
Tbone Tbone is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: NYC
Posts: 19 Tbone User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Tbone
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!

Reply With Quote
  #7  
Old March 22nd, 2003, 12:21 PM
JCMerlin JCMerlin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 126 JCMerlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 29 sec
Reputation Power: 6
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]) + "";


Reply With Quote
  #8  
Old March 22nd, 2003, 02:17 PM
JCMerlin JCMerlin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 126 JCMerlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 29 sec
Reputation Power: 6
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.

Reply With Quote
  #9  
Old March 22nd, 2003, 06:28 PM
Tbone Tbone is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: NYC
Posts: 19 Tbone User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Tbone
Got it working with that last bit of code! Thank you very much I really appreciate it. You're the man.

Reply With Quote
  #10  
Old March 22nd, 2003, 07:40 PM
JCMerlin JCMerlin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 126 JCMerlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 29 sec
Reputation Power: 6

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignFlash Help > PHP variables from MySQL -> Flash


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |