Click to See Complete Forum and Search --> : Images coming from PHP, display in flash?
Webjedikungfu
11-26-2006, 08:53 AM
Hi, I'm trying to display dynamic JPG, GIF, PNG's from my database using php. Sorta at a loss. I checked the Flash "HELP" for a while but came up with nothing that worked. Also googled everything bout "images, Flash, PHP" and "Dynamically displaying images in flash. Came up with nothing. Maybe I'm a bad googler but.....
anyhow below is my simple PHP that shows an image when looked at in browser. I've tried several ways to display it in flash. It works nice if I just place the server location of my actual pic in a "loader Component", But I need it PHP-Dynamic.
~thanks for any help
thumb_1_txt.php
<?php
session_start();
header("Cache-control: private");
if (!$_SESSION['email']) {
echo "You aren't logged in.";
exit();
}
?>
<html>
<body>
<img src="user_files/thumbnail1/<?php echo $_SESSION['thumb_1']; ?>"/>
</body>
</html>
Maybe someone could show me a function in flash that will display this pic, thanks
schizo
11-26-2006, 01:42 PM
There are a number of ways to send a PHP variable to Flash (try to Google that instead). Simply send the URL path of the image to flash, then use the loadMovie() (http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary423.html) method to load in that path. Please note you will likely need to swich to Flash 8 if you want to load in all three of those file types dynamically.
Webjedikungfu
11-26-2006, 04:29 PM
OK thanks, I'll give it a shot again. I tried that, but maybe I goofed it up in my actionscript.
I'm working in flash 8
schizo
11-26-2006, 09:44 PM
If you still have no luck, just post your code... php/html & actionscript.
Webjedikungfu
11-27-2006, 07:47 AM
Thanks for taking the time to help Schizo, I really appreciate it!
Well, I tried some more with no luck. My PHP\HTML code is in my first post. And here is what I'm trying to use for actionscript because it already works for my text data(pulls from MySQL and displays in flash) I tried changing it in different ways to work for images into a flash-loader(no luck), kinda stabbin' in the dark. I'm not sure how to transform this to work for "PHP-JPGs variables"
The JPG "name value" in my MySQL is thumb_1 and the name of the PHP file is thumb_1_txt.php
-----------
ACTIONSCRIPT
---------------
var loadit_lv:LoadVars = new LoadVars();
loadit_lv.load("profile_stuff/PHP_TEXT_files/name_txt.php");
loadit_lv.onData = function(src:String) {
if (src != undefined) {
name_txt.text = src;
} else {
trace("Could not load text file.");
}
};
schizo
11-27-2006, 09:51 AM
Let's try an easier approach. In your PHP document, implement the swf as you normally would, but add a querystring value to each source parameter:
<?php
session_start();
$filename = 'user_files/thumbnail1/'.$_SESSION['thumb_1'];
?>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,65,0" width="890" height="800" id="main" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="main.swf?filename=<?=$filename?>" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="main.swf?filename=<?=$filename?>" quality="high" bgcolor="#ffffff" width="890" height="800" name="main" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
At runtime this would output ...main.swf?filename=image1.jpg...
Then in Flash you can simply reference that variable with _root.filename
Webjedikungfu
11-27-2006, 01:06 PM
So what you are saying is to not display the main.swf in an HTML page like I have it now. Display the main.swf in a PHP page like you showed above? And forget the HTML file altogether. Then it would be easier to get all of my info from MySQL because the file I'm displaying my webpage in has all my variables tied to it?
Do I have that right? And if so, is that easier than trying some more to code a "loadvars with loadmovieclip" to display it? I'm sorry to be troublesome, but just can't get my head around it just yet, I swear I'm tryin'.
Say, for example this is your info:
<img src="user_files/thumbnail1/<?php echo $_SESSION['thumb_1']; ?>"/>
On an actions frame in flash of your swf, what would your actionscript look like to display this correctly coming from a PHP file? If I could see the function you would build that would really help. The PHP part I have already delivers an image, I just need actionscript function for displaying it in flash.
Thanks again
schizo
11-27-2006, 03:38 PM
Well yes, it would go inside the PHP file that outputs HTML. LoadVars would only be useful in this case if you wanted to send data from Flash to PHP (not the other way around like we're trying to do). The actionscript would be as simple as:
var mc:MovieClip = _root.createEmptyMovieClip("mc", _root.getNextHighestDepth());
mc.loadMovie(_root.filename);
Webjedikungfu
11-27-2006, 07:22 PM
cool, I'll give it a shot and let you know, thanks a million schizo
Webjedikungfu
11-28-2006, 10:20 PM
:) Success Schizo!
Well, took me long enough to figure out what you were doing in your examples. And after setting it all up like you said to, it worked like a dream.
1. Changed my main HTML to PHP
2. Modified the new PHP the way schizo said earlier(variables were passed)
3. Added the simple actionscript he gave for an example to my actions frame
And voila! I'm displaying my members pics in their profiles dynamically.
The Macromedia Flash team should sit with someone who does not know how to code at all, and rewrite their "Help" section to make it easier for newcomers to understand. They would have a better product to market.
After seeing Schizo's example, only then did I understand what the documentation in Flash was trying to show me about passing variables.
Schizo you rock! thanks for your time and expertise my friend! I'll be back soon to pick your brain some more when Flash documentation fails. :D
schizo
11-29-2006, 11:02 AM
I'm glad you got it working. I developed a website a couple years ago which described everyday solutions such as this, and provided source files as examples. Unfortunately the low traffic didn't warrant keeping it up. Maybe I'll bring it back someday...