Link to home
Start Free TrialLog in
Avatar of michaelbrewitt
michaelbrewittFlag for United Kingdom of Great Britain and Northern Ireland

asked on

passing php variable to FLASH

this is my php file:
<?

GLObal $test;

$test = "'/Photos/P1010049.jpg'";
echo ("test=" .$test);

?>


this is my flash actionscript:

addressVars = new LoadVars();
addressVars.load("http://www.zzzzzzzzzzzzzz/flash/test.php");
addressVars.onLoad = function() {
      trace(addressVars.test);
image0uri = addressVars.test;

------------------------
the problem is that my flash app does not load the php variable and does not show the image i'm wanting to show. If i replace the last line of the action script with:
image0uri =  '/Photos/P1010049.jpg';

it works perfectly.

Any ideas?

Avatar of LinuxNubb
LinuxNubb
Flag of United States of America image

I don't know squat about flash, but is there a way to echo out variables to see what's set to?

Like an echo image0uri or something, so you can see what it is actually set to? It might help to know if it's blank, or set to some weird unexpected path.
Not too familiar with flash, but if that file with the actionscript in it can be parsed with PHP, then you can simply output the variable directly into the script.  Otherwise, here are some links I found:

https://www.experts-exchange.com/Web/WebDevSoftware/Flash/ - EE flash area
http://flashmx2004.com/forums/index.php?showtopic=1351 - article on passing variables into flash via html.  output the php variable right onto the page that the user is viewing

-Matt
Avatar of TheMaximumWeasel
TheMaximumWeasel

you can pass a vaariable to flash using get

example
--------------------------
<?php

$myvariable = "testvariable stuff here";
?>
<object width="550" height="400">
<param name="movie" value="somefilename.swf">
<embed src="somefilename.swf?myvariable=<?php echo $myvariable; ?>" width="550" height="400">
</embed>
</object>
--------------------------
then the variable is passed to the swf file when it is called.
then you can use the variable myvariable or whatever text is in between the ? and = in the url to the flash file.

Max
$test = urlencode("'/Photos/P1010049.jpg'");
echo ("&test=" .$test);
ASKER CERTIFIED SOLUTION
Avatar of gowni
gowni
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of michaelbrewitt

ASKER

tolgoang - that didn't work.

Anyone else, any more suggestions?

Thanks
Did you try my idea??

Max

PS: I use it on a lot of Flash applications that I have.
In this contrived example, suppose that you have a Flash movie that loads an image file and display the image (using  loadMovie on Flash MX - if you're using Flash 5, think of it as loading another .swf file).  

You want to be able to use the same swf file on many pages to show different images.  Obviously, you need to pass the image filename to Flash.  What can you do?  Since a filename is such a simple text, you can use query string to pass it.  

Assuming the image filename is image1.jpg, located at a folder named images.  And assuming that the Flash movie will use a variable named imageFilename to refer to the file, then we can do this:

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  codebase="http://download.macromedia.com/"  
  WIDTH="250" HEIGHT="300" id="flaMovie1">
  <PARAM NAME=movie VALUE="flaMovie1.swf?imageFilename=images%2Fimage1%2Ejpg">
  <PARAM NAME=quality VALUE=high>
  <PARAM NAME=bgcolor VALUE=#FFFFFF>
  <EMBED src="flaMovie1.swf?imageFilename=images%2Fimage1%2Ejpg"
    quality=high bgcolor=#FFFFFF WIDTH="250" HEIGHT="250" NAME="flaMovie1"
    TYPE="application/x-shockwave-flash"
    PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
  </EMBED>
</OBJECT>

There you see that I appended a query string after the Flash movie filename (flaMovie1.swf).  The query string contains one variable: imageFilename, with the value of images/image1.jpg.  

Note: The %2F is the url encoding for the "/" sign, and %2E is the url encoding for the "." sign.  Since these symbols are unsafe or reserved, we should url encode them, although at the present Flash does not seem to care.  So saying: imageFilename=images%2Fimage1%2Ejpg is essentially the same as saying imageFilename=images/image1.jpg.
I found that after searching google and I tested it and that example works.

Max
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial