Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

passing php variable to FLASH

Posted on 2006-04-18
12
Medium Priority
?
322 Views
Last Modified: 2008-01-09
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?

0
Comment
Question by:michaelbrewitt
10 Comments
 
LVL 9

Expert Comment

by:LinuxNubb
ID: 16482328
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.
0
 
LVL 6

Expert Comment

by:mattjp88
ID: 16482751
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:

http://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
0
 
LVL 4

Expert Comment

by:TheMaximumWeasel
ID: 16482831
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:tolgaong
ID: 16484952
$test = urlencode("'/Photos/P1010049.jpg'");
echo ("&test=" .$test);
0
 
LVL 1

Accepted Solution

by:
gowni earned 100 total points
ID: 16506161
Hi,

Always you need to print the variables with vlaues as query string. Only pre-caution has to be taken is that we need to start the output with "&" so that it adds these variable to the Loadvars object you create in the flash.

For example :

print "&var1=value1&var2=value2";

Suppose you want to post some values to the php script and get the details back, then its better to use

LoadVars.sendAndLoad method.

Gowni


0
 
LVL 1

Author Comment

by:michaelbrewitt
ID: 16510982
tolgoang - that didn't work.

Anyone else, any more suggestions?

Thanks
0
 
LVL 4

Expert Comment

by:TheMaximumWeasel
ID: 16513027
Did you try my idea??

Max

PS: I use it on a lot of Flash applications that I have.
0
 
LVL 4

Expert Comment

by:TheMaximumWeasel
ID: 16513083
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.
0
 
LVL 4

Expert Comment

by:TheMaximumWeasel
ID: 16513086
I found that after searching google and I tested it and that example works.

Max
0
 
LVL 4

Assisted Solution

by:TheMaximumWeasel
TheMaximumWeasel earned 100 total points
ID: 16513112
this page has a sorts of methods:

http://www.permadi.com/tutorial/flashQueryString/

Max
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

575 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question